好吧,使用 ts-jest
27.x.x
,我可以通过 require('ts-jest/utils')
,如下图所示,它存在于 ts-jest 依赖文件夹中:
但是在使用 ts-jest
28.x.x
的较新项目中,当我尝试导入它时,结果如下:
我现在应该怎么做才能使用这些助手?
最佳答案
见 Test helpers关于 mocked
测试助手的文档:
This function is now deprecated and will be removed in 28.0.0. The function has been integrated into
jest-mock
package as a part of Jest 27.4.0, see https://github.com/facebook/jest/pull/12089. Please use the one fromjest-mock
instead.
您应该使用 jest.mocked(item: T, deep = false)而不是 import { mocked } from 'ts-jest/utils'
从 ts-jest
28.0.0 开始,他们删除了 ts-jest/utils
子路径导出。看到这个issue
We are exporting everything from
index.ts
soutils
now can be removed.
关于typescript - 缺少 TS-Jest 实用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72960399/