【发布时间】:2021-04-25 23:22:25
【问题描述】:
我在 React 中有一个代码
$.get('/bin/data', (response) => {
this.data = response;
});
这是我的测试用例:
$document = {
on: jest.fn().mockName('$document.on'),
};
expect(window.$).toBeUndefined();
$ = jest.fn().mockName('$').mockReturnValue($document);
$.get = () => {};
jest.spyOn($, 'get').mockName('$.get').mockImplementation(response => jest.fn()); // not sure what to do here such that callback function is also covered
window.$ = $;
一切正常,但没有覆盖回调函数。
【问题讨论】:
标签: javascript reactjs unit-testing ecmascript-6 jestjs