我的测试遇到了一个神秘的错误。
背景:
我有很多测试文件,适合除我以外的所有人。 在唯一失败的测试中,唯一的问题是这一行:
const spyOnFetch = jest.spyOn(global, 'fetch');
我不知道为什么,但我有这个错误:
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)
你们有什么想法吗?
我试过了:
信息:
节点版本:21.7.2
NPM 版本:10.5.1
纱线版本:3.8.1
笑话版本:29.5.0
解决方案:
Node 版本与我的测试不兼容。 我用的
20.12
和 21.7
不兼容。