在异步函数中测试承诺

时间:2021-04-20 01:28:53

标签: reactjs jestjs

我正在尝试编写一个玩笑测试来测试在异步函数中运行的承诺。我很难找到描述如何做到这一点的资源。

以下是我所拥有的:

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() 内的成功和错误情况下都运行。

0 个答案:

没有答案