Visual studio code 开玩笑;如何消除过梁错误?
我们正在运行一个带有typescript的项目,现在正在考虑添加测试。我们是否能够将TS jest与类型一起使用,或者我们是否需要使用Visual studio code 开玩笑;如何消除过梁错误?,visual-studio-code,jestjs,tslint,Visual Studio Code,Jestjs,Tslint,我们正在运行一个带有typescript的项目,现在正在考虑添加测试。我们是否能够将TS jest与类型一起使用,或者我们是否需要使用any?现在,如果我们使用mock,就会出现linter错误 例如: const emit: Emit = jest.fn() callFunctionWithEmit(emit) expect(emit.mock.calls[0][0]).toEqual({ result: null }) 这是可行的,但是linter告诉我们Emit没有mock属性。
any
?现在,如果我们使用mock,就会出现linter错误
例如:
const emit: Emit = jest.fn()
callFunctionWithEmit(emit)
expect(emit.mock.calls[0][0]).toEqual({
result: null
})
这是可行的,但是linter告诉我们Emit没有mock属性。有什么好方法可以消除这些过梁错误吗
我们将VSCode与这些插件一起使用:
- 漂亮的
- 特斯林特
- 解决这个问题的方法是使用jest.Mock
解决方案如下所示:
const emit: jest.Mock<Emit> = jest.fn()
callFunctionWithEmit(emit)
expect(emit.mock.calls[0][0]).toEqual({
result: null
})
常量emit:jest.Mock=jest.fn()
callFunctionWithEmit(发射)
expect(emit.mock.calls[0][0]).toEqual({
结果:空
})