1

我正在尝试使用 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";

我也在使用反应测试库。

更新

这似乎是我的 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

4

1 回答 1

2

确认这是 CodeSandbox 的问题:https ://github.com/codesandbox/codesandbox-client/issues/513

于 2019-09-25T21:05:57.797 回答