
[英]How to make VSCode detecting moduleNameMapper from Jest (ts-jest)
[英]TS-Jest; how to remove linter errors?
我们正在使用TypeScript运行一个项目,现在正在考虑添加测试。 我们是否可以将TS-jest与类型一起使用,还是需要使用any
? 现在,如果我们使用模拟,我们会收到linter错误。
一个例子:
const emit: Emit = jest.fn()
callFunctionWithEmit(emit)
expect(emit.mock.calls[0][0]).toEqual({
result: null
})
这行得通,但是lint告诉我们,Emit没有模拟属性。 有什么好的方法可以消除这些棉绒错误?
我们将VSCode与以下插件一起使用:
解决此问题的方法是使用jest.Mock。
解决方案如下所示:
const emit: jest.Mock<Emit> = jest.fn()
callFunctionWithEmit(emit)
expect(emit.mock.calls[0][0]).toEqual({
result: null
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.