TypeScript:Property';mockImplementation';在Jest测试中的类型上不存在
我基本上有:TypeScript:Property';mockImplementation';在Jest测试中的类型上不存在,typescript,jestjs,Typescript,Jestjs,我基本上有: // Example.ts class Example { returnSomething() { return false } } export default new Example() 然后在TypeScript Jest测试中,我有以下内容: // Example/__tests__/index.test.ts jest.mock('Example', () => ({ _esModule: true, returnSomething:
// 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 ...
如何让函数的jest包装模拟在测试的TypeScript中正常工作
还有比这更好的吗
(Example.returnSomething as jest.Mock).mockImplementation(() => 'foo')
请参阅链接不再工作请参阅链接不再工作