Skip to content

Files

Latest commit

 

History

History
34 lines (26 loc) · 704 Bytes

no-test-return-statement.md

File metadata and controls

34 lines (26 loc) · 704 Bytes

Pattern: Return statement in test

Issue: -

Description

Tests should not return values. If dealing with asynchronous operations, use async/await syntax instead of returning Promises directly.

Examples

Example of incorrect code:

test("async operation", () => {
  return expect(fetchData()).resolves.toBe(true);
});

it("promise test", () => {
  return somePromise().then(result => {
    expect(result).toBe("value");
  });
});

Example of correct code:

test("async operation", async () => {
  await expect(fetchData()).resolves.toBe(true);
});

it("promise test", async () => {
  const result = await somePromise();
  expect(result).toBe("value");
});