Skip to content

Files

Latest commit

 

History

History
35 lines (27 loc) · 673 Bytes

no-done-callback.md

File metadata and controls

35 lines (27 loc) · 673 Bytes

Pattern: Done callback

Issue: -

Description

Using the done callback for asynchronous tests is error-prone and requires careful handling of assertions. Using async/await or returning promises provides clearer and more reliable test code.

Examples

Example of incorrect code:

test("async test", (done) => {
  fetchData((data) => {
    expect(data).toBe("value");
    done();
  });
});

beforeEach((done) => {
  setupAsync(() => done());
});

Example of correct code:

test("async test", async () => {
  const data = await fetchData();
  expect(data).toBe("value");
});

beforeEach(async () => {
  await setupAsync();
});