Categories
JavaScript Answers

How to fix the For async tests and hooks, ensure “done()” is called; if returning a Promise, ensure it resolves error with Jest and JavaScript?

Spread the love

To fix the For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves error with Jest and JavaScript, we should make sure we use await with promises.

For instance, we write

it("assertion success", async () => {
  const result = await resolvingPromise;
  expect(result).to.equal("promise resolved");
});

to use await to get the resolved value of the resolvingPromise promise.

Then we check the resolve value of the promise with expect and to.equal.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *