【发布时间】:2019-10-04 18:51:04
【问题描述】:
我正在尝试测试是否调用了异步函数(即发即弃)。
Content.js
export async function fireAndForgetFunction() {
...
}
export async function getData() {
...
fireAndForgetFunction()
return true;
}
我想测试fireAndForgetFunction 是否被多次调用。
Current test
import * as ContentFetch from '../Content';
const { getData } = ContentFetch;
const { fireAndForgetFunction } = ContentFetch;
it('test',async () => {
const spy = jest.spyOn(ContentFetch, 'fireAndForgetFunction');
await getData();
expect(spy).toHaveBeenCalled();
})
测试结果报错说
Expected number of calls: >= 1
Received number of calls: 0
我该如何做这个测试?
【问题讨论】:
标签: javascript node.js jestjs