A test waits for a fixed time instead of for the condition it needs

tx0/ts:test-sleeps-fixed-timerecommendedwarningmaintainability/testsdepth fastsmell

What it finds

A fixed wait, such as cy.wait(1000) or a promise around setTimeout, is either too short on a slow machine, which makes the test flaky, or longer than needed, which makes the suite slow. Waiting for the element, request or state itself is both faster and reliable.

Reported, inside tests and hooks, are cy.wait and waitForTimeout with a number, sleep, delay and wait with a number, and new Promise whose executor only calls setTimeout with a number.

From the rule's source, test_sleeps_fixed_time.rs.

Example from the rule's tests
it("shows the banner", async () => {  await sleep(500);tx0 reports: this test waits for a fixed time  expect(banner()).toBe(true);});declare function sleep(ms: number): Promise<void>;declare function banner(): boolean;
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:test-sleeps-fixed-time" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/ts:test-sleeps-fixed-time] reason="..."

tx0 explain tx0/ts:test-sleeps-fixed-time shows the same in the terminal. Found a false positive? Report it.