【发布时间】:2020-01-25 01:25:49
【问题描述】:
我正在尝试使用 Jest 运行测试,但出现此错误:
jest.mock 不是函数
我做错了什么?这是我的 CodeSandbox:https://codesandbox.io/s/polling-hook-demo-9yo8c
请注意,我在 package.json 中配置 Jest:
"setupFilesAfterEnv": [
"./src/test/setupTestsAfterEnv.ts"
]
setupTestsAfterEnv.ts 使用 jest-dom 扩展了 Jest 期望:
import "@testing-library/jest-dom/extend-expect";
我也在使用 react-testing-library。
更新
这似乎是我的 CodeSandbox 配置的问题。我在本地用 create-react-app 尝试了同样的事情,问题就消失了!
这是我的 Github 存储库,其中 Jest 运行良好:https://github.com/nareshbhatia/hooked-on-polling。
然后我在一个新的 CodeSandbox 中导入了这个 repo:https://codesandbox.io/s/hooked-on-polling-2em7g。当我在这个沙盒中运行测试时,我再次得到同样的错误:jest.mock is not a function
【问题讨论】:
标签: reactjs jestjs react-testing-library codesandbox