Skip to content

Tests rules

Reports an async callback of describe, context, or suite in Jest, Mocha, and Cypress files, and a call in a suite of a local async function that declares tests after an await.

On in the recommended and all configs.

The runner collects the tests of a suite when it calls the callback, and it does not wait for a promise. A test declared after an await never runs, and nothing reports it.

Make the suite callback synchronous. Move the async setup into a beforeAll or beforeEach hook, or into the test that needs it.

describe("cart", async () => { const user = await login(); it("adds", run); }) reports awaitInSuite. Write let user; beforeAll(async () => { user = await login(); }); in the suite.

Reports the first statement that runs after the done callback of an it, specify, or test case: in the same block, or after the block that holds the call.

On in the recommended and all configs.

The runner ends the test when done runs. A statement after it runs while the next test starts, so its assertions and errors land in the wrong test or nowhere.

Move the code above the call of done, or return a promise instead of taking done.

it("saves", (done) => { save(); done(); check(); }) reports afterDone on check();.

Reports a row of a parameterized Bun, Jest, or Vitest test or suite that repeats an earlier row of the same array literal, token for token. The fix deletes the copies.

On in the recommended and all configs. eslint --fix fixes it.

A repeated row runs the same case twice. It costs time and suggests a case that someone meant to write and did not.

Delete the copy, or change it to the case it was meant to test.

test.each([1, 2, 1])("adds %d", run) reports duplicate on the second 1.

Reports a test whose static title repeats the title of an earlier test of the same suite, including the tests that a local function declares when the suite calls it.

On in the recommended and all configs.

Two tests with one title look like one test in a report, so a failure points to the wrong test.

Give each test of a suite its own title, or delete the copy.

it("adds", a); it("adds", b); reports duplicate on the second title.

Reports a test whose body starts with if (condition) return; and goes on with more statements, in Mocha, Vitest, Playwright, node:test, and Bun files.

On in the recommended and all configs.

A test that returns early passes without checking anything, and the report counts it as passed instead of skipped.

Skip the test through the framework, so the report shows it as skipped: this.skip() in Mocha, the context’s skip() in Vitest and node:test, test.skip(condition) in Playwright, and test.skipIf(condition) in Bun.

it("pays", function () { if (!ready) return; pay(); }) reports mocha. Write if (!ready) { this.skip(); }.

Reports a file named *.test.*, *.spec.*, or *.cy.* that declares no test.

On in the recommended and all configs.

A test file without tests passes and checks nothing, so it hides that the tests it should hold are gone.

Add the tests that the file is named for, or delete the file.

A cart.test.ts that only exports helpers reports empty. Move the helpers to a file without the test suffix.

Reports an empty table of a parameterized Bun, Jest, or Vitest test or suite: an empty array literal, or a variable whose one value is an empty array that nothing changes before the call.

On in the recommended and all configs.

A parameterized test runs its body once per row. With no rows the body never runs, and the run still passes.

Add the cases to the table, or delete the test.

test.each([])("adds %d", run) reports empty. Write test.each([1, 2])("adds %d", run).

Reports a test or suite with a callback whose title is an empty or blank string.

On in the recommended and all configs.

The title is what a failure report shows. An empty title gives the reader nothing to find the failing test by.

Name the behavior that the test checks.

it("", run) reports empty. Write it("adds the tax to the total", run).

Reports .only on describe, context, it, specify, and test, and on Playwright test.describe with its parallel and serial modifiers.

On in the recommended and all configs.

An exclusive test makes the runner skip every other test of the file or the run, so the suite passes while most of it never runs.

Remove .only before you commit.

it.only("adds", run) reports exclusive. Write it("adds", run).

Reports fixed Cypress and Playwright waits in test-related files.

On in the recommended and all configs.

A fixed delay can be too short on a busy machine and wastes time when the page is already ready.

Wait for the request, element, or condition that the next assertion depends on.

cy.wait(1000) reports a finding. Wait for an aliased request or a visible element instead.

Reports { force: true } on a Cypress or Playwright action, such as click or type.

On in the recommended and all configs.

A forced action skips the checks that the element is visible, enabled, and not covered, so the test passes where a user could not act.

Remove the option, and wait for the element to be ready, or fix what covers it.

cy.get("button").click({ force: true }) reports force. Write cy.get("button").should("be.visible").click().

Reports a vi.mock() or vitest.mock() call that is not a statement of its own at the top of the module, such as one inside a function, a block, or an expression.

On in the recommended and all configs.

Vitest moves every vi.mock() call to the top of the file before the imports run. A call inside a test or a condition still runs first and for every test, so it cannot mock for one test or at run time.

Move the call to the top level of the module, or use vi.doMock() to mock at run time.

it("reads", () => { vi.mock("./store"); }) reports scope. Move vi.mock("./store"); to the top of the file, or write vi.doMock("./store").

Reports this.timeout(value) inside a Mocha suite, test, or hook when the value is a number above 2147483647, in files that import chai.

On in the recommended and all configs.

Timers take at most 2147483647 milliseconds. A larger timeout overflows, so the test fails at once instead of waiting longer.

Pass 0 to turn the timeout off, or pass a value of 2147483647 or less.

this.timeout(3000000000) reports overflow. Write this.timeout(0) to turn the timeout off.

Reports jest.retryTimes() in files that use Jest, and this.retries() inside a Mocha describe or context suite.

On in the recommended and all configs.

A retry turns a flaky test green without fixing why it fails, so a real race or leak stays in the code.

Find why the test fails on the first try and fix the test or the code. Delete a test that cannot be made stable.

jest.retryTimes(3); reports retry. Make the test pass on its first run, and delete the call.

Reports debug commands in test-related files: cy.pause(), cy.debug(), and .pause() and .debug() on a Cypress chain, Playwright page.pause(), and the Testing Library screen.debug(), screen.logTestingPlaygroundURL(), debug() from render(), prettyDOM(), and logRoles(). The fix deletes the command.

On in the recommended and all configs. eslint --fix fixes it.

A debug command stops a run to wait for a person or floods the log. Left in a test, it blocks CI or hides the output that matters.

Delete the command before you commit.

cy.get("button").debug().click(); reports debug. The fix writes cy.get("button").click();.

Reports a skipped test or suite, such as it.skip or xdescribe, with no comment that gives a reason on the line above, on its line, or on the line below.

On in the recommended and all configs.

A skipped test stops checking its code. Without a reason, nobody knows when to turn it back on or whether to delete it.

Delete the test, fix it so it runs, or write the reason in a comment next to it.

it.skip("adds", run) reports skipped. Add // Waits for the new tax table. on the line above, or delete the test.

Reports three or more it or test cases of one block whose bodies match token for token except for at most three literal values.

On in the all config.

Copies of one test differ only in their data, so a reader must compare them line by line, and a fix must change each copy.

Write one test with test.each and a table of the values that differ.

Three tests that each call add(1, 2), add(2, 3), and add(3, 4) and compare the result report table on the first title. Write test.each([[1, 2, 3], [2, 3, 5], [3, 4, 7]])("adds %d and %d", ...).

Reports a lifecycle hook of a describe or context body that sits among or below its test cases and suites. An after hook may sit above or below them, but the after hooks of one suite stay in one group.

On in the all config.

A reader expects the setup of a suite before its tests. A hook between tests runs for all of them, which its place hides.

Move the before hooks above the first test of the suite, and keep the after hooks together above or below the tests.

describe("cart", () => { it("adds", run); beforeEach(reset); }) reports before. Move beforeEach(reset) above the it call.

Reports a Testing Library screen query of the wrong kind: queryBy* in a presence assertion, getBy* in an absence assertion, and getBy* or findBy* that waitForElementToBeRemoved reads.

On in the recommended and all configs. eslint --fix fixes it.

A getBy* query throws when the element is missing, so an absence assertion never sees a missing element. A queryBy* query returns null, so a presence failure loses the error that lists the page.

Use getBy* to assert that an element is present, and queryBy* to assert that it is absent or to wait for it to go.

expect(screen.getByText("Saved")).not.toBeInTheDocument() reports absence. Write expect(screen.queryByText("Saved")).not.toBeInTheDocument().