typescript - TypeScript:Jest 测试中的类型上不存在属性“mockImplementation”
问题描述
我基本上有这个:
// Example.ts
class Example {
returnSomething() {
return false
}
}
export default new Example()
然后在 TypeScript Jest 测试中我有这个:
// Example/__tests__/index.test.ts
jest.mock('Example', () => ({
_esModule: true,
returnSomething: jest.fn(() => true)
isFeatureEnabled: jest.fn(),
}))
// then down below:
it('some test', () => {
Example.returnSomething.mockImplementation(() => 'foo')
})
但我收到了这个错误:
Property 'mockImplementation' does not exist on type ...
对于这个测试,如何让函数的开玩笑包装的模拟在 TypeScript 中正常工作?
还有什么比这更好的吗?
(Example.returnSomething as jest.Mock).mockImplementation(() => 'foo')
解决方案
推荐阅读
- javascript - 防止 Next.js 生成某些路径文件
- ios - 使用 Apple ID 登录时显示无效的 responseType
- javascript - 如何从ajax布尔值中选择值
- amazon-ec2 - 在 aws 中没有 http 时,路由 53 域无法工作
- php - 具有百分比匹配的 SQL Like 运算符
- ios - 当我在 Xcode 11 中将 swift 4.2 转换为 swift 5 时继续加载
- java - 如何在运行时使用多态性根据它的实例加载片段?
- java - 2 Java 中的 Processing.org 线程
- php - Laravel - 使用两个枢轴连接三个表的雄辩方式
- android - 我可以在另一个 android 应用程序中使用 APK 吗?