Closed pprasanth closed 3 years ago
Try adding
"resetMocks": false,
to your package.json jest
config as mentioned here: https://github.com/jefflau/jest-fetch-mock/issues/184#issuecomment-781421460
I did and it resolved the issue.
@cam8001 Thanks, that worked for me too.
For those who actually want to use resetMocks
, this approach worked for us. In your test setup file:
import fetchMock from 'jest-fetch-mock';
beforeEach(() => {
// we have `resetMocks` as true, so between each test, it is reset
fetchMock.enableMocks();
// trial and error found that need to do both enable and do before each test
fetchMock.doMock();
});
We previously had enableMocks
set like this, but were seeing the error here. Adding the following doMock
appears to "re-enable" them. From an API expectation POV, I'd expect enableMocks
to do whatever doMock
is doing, in that it would always re-enable, even if resetMocks
is true. But anyhow, this is an OK enough work around and wanted to share for others who may not want to disable resetMocks
.
Tried run test case with mock enabled for one of my action creator and failing due to isMocking is not a function or return value is not iterable.
Versions:
setupJest.js
require('jest-fetch-mock').enableMocks();
code:test code:
Error: