Tests rules
no-async-suite-callbacks
Section titled “no-async-suite-callbacks”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.
What to do
Section titled “What to do”Make the suite callback synchronous. Move the async setup into a beforeAll or beforeEach hook, or into the test that needs it.
Example
Section titled “Example”describe("cart", async () => { const user = await login(); it("adds", run); }) reports awaitInSuite. Write let user; beforeAll(async () => { user = await login(); }); in the suite.
no-code-after-done
Section titled “no-code-after-done”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.
What to do
Section titled “What to do”Move the code above the call of done, or return a promise instead of taking done.
Example
Section titled “Example”it("saves", (done) => { save(); done(); check(); }) reports afterDone on check();.
no-duplicate-test-rows
Section titled “no-duplicate-test-rows”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.
What to do
Section titled “What to do”Delete the copy, or change it to the case it was meant to test.
Example
Section titled “Example”test.each([1, 2, 1])("adds %d", run) reports duplicate on the second 1.
no-duplicate-test-titles
Section titled “no-duplicate-test-titles”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.
What to do
Section titled “What to do”Give each test of a suite its own title, or delete the copy.
Example
Section titled “Example”it("adds", a); it("adds", b); reports duplicate on the second title.
no-early-test-return
Section titled “no-early-test-return”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.
What to do
Section titled “What to do”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.
Example
Section titled “Example”it("pays", function () { if (!ready) return; pay(); }) reports mocha. Write if (!ready) { this.skip(); }.
no-empty-test-file
Section titled “no-empty-test-file”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.
What to do
Section titled “What to do”Add the tests that the file is named for, or delete the file.
Example
Section titled “Example”A cart.test.ts that only exports helpers reports empty. Move the helpers to a file without the test suffix.
no-empty-test-table
Section titled “no-empty-test-table”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.
What to do
Section titled “What to do”Add the cases to the table, or delete the test.
Example
Section titled “Example”test.each([])("adds %d", run) reports empty. Write test.each([1, 2])("adds %d", run).
no-empty-test-titles
Section titled “no-empty-test-titles”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.
What to do
Section titled “What to do”Name the behavior that the test checks.
Example
Section titled “Example”it("", run) reports empty. Write it("adds the tax to the total", run).
no-exclusive-tests
Section titled “no-exclusive-tests”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.
What to do
Section titled “What to do”Remove .only before you commit.
Example
Section titled “Example”it.only("adds", run) reports exclusive. Write it("adds", run).
no-fixed-test-waits
Section titled “no-fixed-test-waits”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.
What to do
Section titled “What to do”Wait for the request, element, or condition that the next assertion depends on.
Example
Section titled “Example”cy.wait(1000) reports a finding. Wait for an aliased request or a visible element instead.
no-forced-ui-actions
Section titled “no-forced-ui-actions”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.
What to do
Section titled “What to do”Remove the option, and wait for the element to be ready, or fix what covers it.
Example
Section titled “Example”cy.get("button").click({ force: true }) reports force. Write cy.get("button").should("be.visible").click().
no-nested-vitest-mock
Section titled “no-nested-vitest-mock”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.
What to do
Section titled “What to do”Move the call to the top level of the module, or use vi.doMock() to mock at run time.
Example
Section titled “Example”it("reads", () => { vi.mock("./store"); }) reports scope. Move vi.mock("./store"); to the top of the file, or write vi.doMock("./store").
no-overflowing-test-timeout
Section titled “no-overflowing-test-timeout”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.
What to do
Section titled “What to do”Pass 0 to turn the timeout off, or pass a value of 2147483647 or less.
Example
Section titled “Example”this.timeout(3000000000) reports overflow. Write this.timeout(0) to turn the timeout off.
no-test-retries
Section titled “no-test-retries”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.
What to do
Section titled “What to do”Find why the test fails on the first try and fix the test or the code. Delete a test that cannot be made stable.
Example
Section titled “Example”jest.retryTimes(3); reports retry. Make the test pass on its first run, and delete the call.
no-ui-test-debugging
Section titled “no-ui-test-debugging”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.
What to do
Section titled “What to do”Delete the command before you commit.
Example
Section titled “Example”cy.get("button").debug().click(); reports debug. The fix writes cy.get("button").click();.
no-unexplained-test-skips
Section titled “no-unexplained-test-skips”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.
What to do
Section titled “What to do”Delete the test, fix it so it runs, or write the reason in a comment next to it.
Example
Section titled “Example”it.skip("adds", run) reports skipped. Add // Waits for the new tax table. on the line above, or delete the test.
prefer-test-table
Section titled “prefer-test-table”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.
What to do
Section titled “What to do”Write one test with test.each and a table of the values that differ.
Example
Section titled “Example”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", ...).
test-hooks-first
Section titled “test-hooks-first”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.
What to do
Section titled “What to do”Move the before hooks above the first test of the suite, and keep the after hooks together above or below the tests.
Example
Section titled “Example”describe("cart", () => { it("adds", run); beforeEach(reset); }) reports before. Move beforeEach(reset) above the it call.
testing-library-queries
Section titled “testing-library-queries”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.
What to do
Section titled “What to do”Use getBy* to assert that an element is present, and queryBy* to assert that it is absent or to wait for it to go.
Example
Section titled “Example”expect(screen.getByText("Saved")).not.toBeInTheDocument() reports absence. Write expect(screen.queryByText("Saved")).not.toBeInTheDocument().