我有一个对象配置,我在其中向函数发送函数回调。
test('should create a ComponentMockwith the needed config', () => {
const config: EqListeningPlayerConfig = {
// more options
myCallback: jasmine.anything()
};
sut.doYourThing(config);
expect(ComponentMock.create).toHaveBeenCalledWith(config);
});
我遇到的问题是,在更新到最新的 jest/jasmine 后,我在
myCallback: jasmine.anything()
中收到此错误:How to fix Type 'AsymmetricMatcher' is not assignable to type '() => void'. in jasmine/jest
如果我忽略该行
@ts-ignore
我的测试继续工作,但我想知道为什么 linter 会这样说以及如何解决它,因为我真的不明白它。
最佳答案
我在我的应用程序中遇到了同样的问题,我通过将麻烦的类型映射到任何 jasmine.anything() as any
来解决它.也许它也能解决你的问题。
test('should create a ComponentMockwith the needed config', () => {
const config: EqListeningPlayerConfig = {
// more options
myCallback: jasmine.anything() as any // < --- here is what solved my issue
};
sut.doYourThing(config);
expect(ComponentMock.create).toHaveBeenCalledWith(config);
});
关于jasmine - 如何修复类型 'AsymmetricMatcher<any>' 不能分配给类型 '() => void' 。在 Jasmine /开 Jest ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59215686/