Open ghasemikasra39 opened 3 years ago
I've found the answers from https://github.com/itinance/react-native-fs/issues/404 really helpful - namely:
__mocks__
folder, create a file entitled react-native-fs.js
export default {
readFile: jest.fn(),
...
}
You may need to add a more complete mock however, as detailed here: https://github.com/itinance/react-native-fs/issues/404#issuecomment-360170580
I did not have to add react-native-fs
to transformIgnorePatterns
either.
No luck with adding
jest.mock('react-native-fs', () => {
return {
readFile: jest.fn(),
};
});
to setupFiles
this is so strange.
Well in fact I have several mocks in the same setup file. When I move mockRNFS
from the last one to the first one, it works. How can the order of mocking matter? Maybe it is a jest bug.
For future readers that run into an issue with mocking react-native-fs
, I do my test mocks like:
jest.mock("react-native-fs", () => {
const RNFS = {
readFileAssets: async () => {
return "testdata"
},
}
return RNFS
})
I get this error only in testing environment
mocking did not help:
adding
react-native-fs
totransformIgnorePatterns
did not helpenv: