Open ghasemikasra39 opened 3 years ago
same issue, not able to run my jest tests.
Is there any solution? got the same error on yarn test
Could try a module level manual mock https://jestjs.io/docs/en/manual-mocks#mocking-node-modules . Creating mocks in the root __mocks__
folder prevents jest from even looking at the real module to begin with. (For automatic mocks, jest scans the real module, then tries to generate a mock of the same structure.)
I did it like this -
testHelpers/rn-fetch-blob-mock.js -- `let RNFetchBlob = jest.mock('rn-fetch-blob');
RNFetchBlob.fetch = jest.fn(); RNFetchBlob.wrap = jest.fn();
export default {RNFetchBlob};`
jest.setup.js --
jest.mock('rn-fetch-blob', () => require('./testHelpers/rn-fetch-blob-mock.js'), );
package.json --
"jest": { "preset": "react-native", "transformIgnorePatterns": [ "node_modules/(?!rn-fetch-blob)" ], "setupFiles": [ "<rootDir>/jest.setup.js", "./node_modules/react-native-gesture-handler/jestSetup.js" ] }
This is how i was able to mock fs.unlink:
jest.mock('rn-fetch-blob', () => {
return {
__esModule: true,
default: {
fs: {
unlink: jest.fn(),
},
},
};
});
I run my test and get this error:
Adding
rn-fetch-blob
totransformIgnorePatterns
, changed the error toadding this did not help: