如何修复类型“AmetryMatcher<any>”不可分配给类型“() => void”。在茉莉花/笑话中

dis*_*nte 5 jasmine jestjs ts-jest

我有一个对象配置,我在其中向函数发送函数回调。

test('should create a ComponentMockwith the needed config', () => {
        const config: MyConfig = {
           // more options
          myCallback: jasmine.anything()
        };

        sut.doYourThing(config);

        expect(ComponentMock.create).toHaveBeenCalledWith(config);
      });
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是,更新到最新的 jest/jasmine 后,我收到以下错误myCallback: jasmine.anything()

如何修复类型“AmetryMatcher”不可分配给类型“() => void”。在茉莉花/笑话中

如果我忽略该行,@ts-ignore我的测试将继续工作,但我想知道 linter 为什么这么说以及如何修复它,因为我真的不明白它。

Mat*_*ska 4

我在我的应用程序中遇到了同样的问题,我通过将麻烦的类型映射到任何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);
      });
Run Code Online (Sandbox Code Playgroud)