I’ve encountered an error with my tests from a mysterious way.
Context :
I have a lot of testing files that work for everyone expect me.
In the only test that fail, the only issue is this line :
const spyOnFetch = jest.spyOn(global, 'fetch');
I don’t know why but I have this error :
FAIL Native ...learner-native-app/src/sections/settings/pages/DeleteAccount/DeleteAccount.test.tsx
● Test suite failed to run
TypeError: Cannot assign to read only property 'fetch' of object '[object global]'
at Object.restore (node_modules/jest-mock/build/index.js:786:35)
at Set.forEach (<anonymous>)
(node:34885) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Do you guys have an idea ?
I tried :
- Change my node version with nvm
- Delete homebrew node version
- Updating npm version
- Recloning the project
- Updating yarn
Information :
-
Node version : 21.7.2
-
NPM version : 10.5.1
-
yarn version : 3.8.1
-
Jest version : 29.5.0
2
Answers
Solution :
Node version is not compatible with my tests. I used
20.12
and21.7
are not compatible.Jest 29.7.0 fixes this, seems it’s something to do with how it sandboxes between tests.