I took the exact code sample from jest-fetch-mock npm package example and I cannot make it fail. Can anyone tell me what am I doing wrong?
This is my code:
require('jest-fetch-mock').enableMocks();
const APIRequest = (who) => {
if (who === 'google') {
return fetch('https://google.com').then((res) => res.json());
} else {
return 'no argument provided';
}
};
describe('testing api', () => {
beforeEach(() => {
fetch.resetMocks();
});
it('calls google and returns data to me', () => {
fetch.mockResponseOnce(JSON.stringify({ data: '12345' }));
//assert on the response
APIRequest('google').then((res) => {
expect(res.data).toEqual('not 12345');
});
});
});
Even if, clearly, my mock response for the fetch doesn't match my expected result, jest still says the test passed , why? It tells me above the "test passed" section that it received something else than what was expected, but the test still shows "passed", why ? How can I make it fail in this situation, how it is actually expected in this situation.