class Foo { addListener = (callback: () => number) => { } func = () => { this.addListener(() => 1); }}test('working', () => { const foo = new Foo(); const mockAddListener = jest.spyOn(foo, 'addListener'); // spy on foo.addListener mockAddListener.mockImplementation(() => { }); // replace the implementation if desired foo.func(); // will call addListener with a callback const callback = mockAddListener.mock.calls[0][0]; expect(callback()).toEqual(1); // SUCCESS}); 这篇关于开玩笑的typescript属性嘲笑在类型上不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-12 15:20