我正在尝试编写一个玩笑测试来测试在异步函数中运行的承诺。我很难找到描述如何做到这一点的资源。
以下是我所拥有的:
const foo = async (client) => {
const update = data => {};
await client.query({
query: QUERY,
variables: {
x: xVal,
y: yVal,
},
}).then(response => {
update({ response });
}).catch(error => {
update({ [] });
});
}
...
fetch: () => {
foo(client)
},
基本上我需要测试 fetch()
,然后确认 update()
在 foo()
内的成功和错误情况下都运行。