skip to content

Test Runner and Commands

The command chain end to end: what a spec enqueues, what each step yields, which steps retry, and what resets between tests. Most Cypress mistakes start here.

on this pageshow

explore

questions

page 2 of 2

How far should a Cypress 16 suite lean on `visibilityStrategy: 'legacy'`?

level: principalimportance: should knowfreq 34%

basics

~20 s

Treat it as a short migration crutch, not a setting. It is deprecated and scheduled for removal, so use it to keep named specs green through one upgrade while you rewrite the assertions that depended on ancestor clipping.

open as a page

In a Cypress suite, how far should `.trigger()` stand in for a real action command?

level: principalimportance: should knowfreq 36%

basics

~20 s

Cypress's .trigger() dispatches the named event and nothing else: no default browser action, no companion events, no focus change. Use it where the behaviour under test really is a listener, and keep real action commands wherever the browser default is the point.

open as a page

How far should a Cypress suite go to work around not being able to store command results?

level: principalimportance: should knowfreq 38%

basics

~20 s

Only as far as the chain naturally goes. Treat deep callback nesting as a signal that the spec is discovering what it should already know, and move that knowledge into seeded data or a retried assertion.

open as a page

Cypress clears aliases before every test — when should a suite share setup instead?

level: principalimportance: should knowfreq 33%

basics

~20 s

Share setup only when the value is read-only for the whole file, expensive to produce, and identical for every test. Anything a test can mutate stays per test, because a shared mutable value makes the suite order-dependent and unreproducible locally.

open as a page

When should a Cypress suite be allowed to set testIsolation: false?

level: principalimportance: should knowfreq 38%

basics

~20 s

Only for a small, read-only block where page loads dominate and no test mutates state another reads, approved on the condition that every test in it still passes under .only. Never at the root config.

open as a page

Which shared Cypress helpers should be registered with Cypress.Commands.addQuery()?

level: principalimportance: should knowfreq 36%

basics

~20 s

Only helpers that are a pure, synchronous, repeatable read of the page or browser state. Anything that acts, awaits, or drives other cy commands must be a command — and a command stops the chain relinking after it.

open as a page

In Cypress, how does an action command decide an element is still animating?

level: middleimportance: nice to knowfreq 33%

basics

~20 s

It measures rather than listens. On each retry Cypress records the element's position and compares the last two samples; if they are more than animationDistanceThreshold apart, five pixels by default, the element counts as animating.

open as a page

In Cypress, why does a `.click()` report the event firing on the button's inner span?

level: middleimportance: nice to knowfreq 34%

basics

~20 s

Cypress fires at a coordinate, not at a node. The click lands on whatever element is topmost at that point, so a child covering the button's centre gets the event, and the Command Log names it. Focus still goes to the button.

open as a page

In Cypress 16, what replaces the removed cy.end() command?

level: middleimportance: nice to knowfreq 19%

basics

~20 s

Nothing replaces it. cy.end() ended a chain by yielding null, which was never needed, because a Cypress chain is already terminated as soon as the next cy command starts a new one. In Cypress 16 you simply delete the calls.

open as a page

What does Cypress's .as('total', { type: 'static' }) store that a default alias does not?

level: middleimportance: nice to knowfreq 24%

basics

~20 s

A static alias stores the resolved value once, at the moment .as() runs, instead of the query chain that produced it. cy.get('@total') then returns that frozen value on every read rather than re-deriving it from the page.

open as a page

Why does Cypress reject testIsolation: false on an it block but accept it on describe?

level: middleimportance: nice to knowfreq 28%

basics

~20 s

Because the browser-context reset happens at the boundary between tests, not inside one. Cypress resolves it per suite, so a per-test value would be ambiguous, and it errors that testIsolation can only be overridden from a suite-level override.

open as a page

In Cypress, why does a `while` loop around `cy.get()` hang the spec instead of retrying?

level: seniorimportance: nice to knowfreq 31%

basics

~20 s

Because the loop never gives control back. Cypress only starts running commands once the spec body finishes, so every iteration piles more commands onto the queue, the exit condition can never flip, and the browser eventually gives out.

open as a page

In Cypress, why does a value returned from a .each() callback never reach the next command?

level: seniorimportance: nice to knowfreq 24%

basics

~20 s

Cypress's .each() always yields back the array-like subject it was given, whatever the callback returns, and it deliberately breaks the subject link to any chain the callback started. Only returning exactly false means something: it ends the loop early.

open as a page

Should a Cypress test behave differently when Cypress.currentRetry is greater than zero?

level: principalimportance: nice to knowfreq 22%

basics

~20 s

Almost never for anything that changes what is asserted. Branching on the attempt number makes the retry a different test, so a green second attempt no longer tells you the first failure was environmental. Extra diagnostics are the defensible exception.

open as a page

showing 31–44 of 44