Skip to content
This repository was archived by the owner on Aug 3, 2023. It is now read-only.

Commit 24546f2

Browse files
committed
Add test to verify that content-type mismatches work as expected
1 parent 55e6fea commit 24546f2

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/index.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,40 @@ describe('successful requests', () => {
212212
}, networkTimeout);
213213
});
214214

215+
test('it sets data to `null` if the contentType does not parse the data', done => {
216+
fetchMock.get(
217+
'/test/succeeds/second-mismatch-content-type',
218+
new Promise(resolve => {
219+
resolve(successfulResponse());
220+
})
221+
);
222+
223+
expect.assertions(2);
224+
const afterFetchMock = jest.fn();
225+
226+
mount(
227+
<Fetch
228+
url="/test/succeeds/second-mismatch-content-type"
229+
afterFetch={afterFetchMock}
230+
responseType="json"
231+
/>
232+
);
233+
234+
setTimeout(() => {
235+
expect(afterFetchMock).toHaveBeenCalledTimes(1);
236+
expect(afterFetchMock).toBeCalledWith(
237+
expect.objectContaining({
238+
url: '/test/succeeds/second-mismatch-content-type',
239+
error: null,
240+
failed: false,
241+
didUnmount: false,
242+
data: null
243+
})
244+
);
245+
done();
246+
}, networkTimeout);
247+
});
248+
215249
test('it accepts a custom `responseType` as a function, and calls afterFetch with the right arguments', done => {
216250
fetchMock.get(
217251
'/test/succeeds/secondpls',

0 commit comments

Comments
 (0)