I once lost days to a Cypress error that was lying to me. The request it swore never happened was sitting in the command log the whole time, and Cypress kept printing this anyway:
CypressError: Timed out retrying after 30000ms:
`cy.wait()` timed out waiting `30000ms` for the 1st request to the route: `saveReport`.
No request ever occurred.
That's the most misleading error Cypress produces, because it reads like a statement of fact about the network, and it usually isn't one. In my experience it has four distinct causes, and only one of them means what the message says. Fix the wrong one and you get the spec we've all opened at least once: three nested waits and a cy.wait(2000) on top.
So let's get to the grain here: four causes, one error message, and a way to tell them apart in about a minute.
1. You aliased after the trigger
The classic, the one everybody knows about. Except it hides beautifully inside a helper.
export function openReport() {
cy.get('[data-cy="report-btn"]').click()
cy.intercept('POST', '**/api/report/generate').as('generate')
cy.wait('@generate')
}
click() → the request leaves → cy.intercept starts listening → cy.wait waits for something that may already be gone.
The click fires the request. cy.intercept registers a route matcher for requests that happen after it's set up. Cypress commands queue, so the ordering is exactly as written: click, then start listening. Fast backend, no request. Slow backend, request caught. This is the one that "only fails in CI" (four words every QA loves to hear), because CI is often faster on the network hop than your laptop tunnelling to a remote environment.
You won't spot it by reading the spec, because the spec just says openReport() and looks innocent. The fix is architectural: a helper that waits on a request must own the trigger, not follow it.
export function withIntercept(
method: string,
route: string,
alias: string,
trigger: () => void,
) {
cy.intercept(method, route).as(alias)
trigger()
return cy.wait(`@${alias}`)
}
withIntercept('POST', '**/api/report/generate', 'generate', () => {
cy.get('[data-cy="report-btn"]').click()
})
Take the trigger as a callback. Now the signature enforces the ordering, and no caller can get it wrong. When I converted a set of shared helpers to this shape, a whole family of intermittent failures across unrelated specs disappeared in one commit. That's how you know it was a helper-level race rather than a spec-level one.
2. A spec-local handler ended the chain
This is the one from the top of the post. It cost me the most time, so I'll spell it out.
Suppose your support file sets up a broad intercept that several helpers wait on:
cy.intercept('POST', '**/api/**').as('apiCalls')
Then in one spec you want to inspect a specific response, so you add:
cy.intercept('POST', '**/api/report/generate', (req) => {
req.continue((res) => {
expect(res.statusCode).to.eq(200)
})
})
Now the shared @apiCalls alias stops resolving for that route, and every helper that waited on it fails with No request ever occurred. Including helpers in the same spec that have nothing to do with reports.
You're asking "how can one intercept in one spec break helpers that never even heard of it?", basically because Cypress runs matching route handlers as a chain, most recently registered first:
Your spec-local handler → runs first, calls req.continue() with a callback → completes the request right there
@apiCalls, registered earlier → never gets its turn
req.reply() does the same. Any handler that takes over responsibility for the response completes the request from that handler. Your spec-local intercept didn't add an observer. It took the request off the shared route.
The fix: stay pure middleware. Observe the response through the event hook and let the chain carry on past you.
cy.intercept('POST', '**/api/report/generate', (req) => {
req.on('before:response', (res) => {
expect(res.statusCode).to.eq(200)
})
})
Same access to the response, same ability to mutate it, but this handler doesn't terminate the chain, so the shared alias still fires. req.on('before:response') is the tool you actually wanted almost every time you reached for req.continue. Keep req.continue and req.reply for when you really intend to own the request.
How to spot it: the failing wait is on a broad or shared alias, the failure showed up right after somebody added a narrow intercept, and the request is plainly visible in the command log (yes, the whole time). If Cypress shows you the request and still says it never occurred, you're looking at a chain-ownership problem. Not a network problem.
3. The save only fires when the value changed
Not a race at all, and no amount of intercept restructuring will help.
Plenty of forms are wired so the save request is skipped when the submitted value is identical to the current one. Data-entry grids, inline editors, autosave fields, "commit" flows: all of them commonly diff before sending. Your test types 42 into a cell that already contains 42, the app correctly does nothing, and your wait times out.
The tell is that the test passes once and then fails forever, or passes on a freshly restored environment and fails on a reused one:
First run → the value changes → the save request fires → green
Every run after that → same value, so it's a no-op → no request → red
If your reaction to that is "so the fix is to restore the database", careful (tempting, I know). That hides the fragility instead of removing it.
Three real options, in order of preference:
Make the input relative to current state.
cy.get('[data-cy="qty"]').invoke('val').then((current) => {
const next = Number(current) + 1
cy.get('[data-cy="qty"]').clear().type(String(next))
})
Reset the fixture in a beforeEach, so the starting value is known instead of inherited.
Assert on the outcome instead of the request. If what you care about is that the total updated, wait on the total. A request is an implementation detail; the rendered total is the behaviour. Waiting on requests is a means to an end, and specs that wait on the network for things they could observe in the DOM are harder to maintain for no gain.
4. A 204, and an event that never comes
Some endpoints acknowledge and hand off. You POST to start a job, the server returns 204 No Content, and the actual result arrives later over a different channel (a websocket push, a poll, a second request) when there is a result to send. In the empty or no-op case, nothing is ever sent.
So a waiter built like this hangs:
cy.intercept('POST', '**/api/procedure/run').as('run')
cy.intercept('POST', '**/api/procedure/result').as('result')
cy.get('[data-cy="run"]').click()
cy.wait('@run')
cy.wait('@result')
@run resolves. @result times out, because for this input the server had nothing to report and correctly sent nothing.
A 204 is an acknowledgement. Not a result. So never wait on an event the server only sends sometimes. Wait for what the application can't finish without: the acknowledgement you can observe, then the visible end state.
cy.intercept('POST', '**/api/procedure/run').as('run')
cy.get('[data-cy="run"]').click()
cy.wait('@run').its('response.statusCode').should('be.oneOf', [200, 204])
cy.get('[data-cy="run-spinner"]').should('not.exist')
cy.get('[data-cy="status"]').should('contain', 'Completed')
Chase this one down properly before you rewrite selectors. Two specs I inherited were tagged as data-source problems for months (months!). Both were this: a 204 hand-off and a waiter listening for an event that only exists on the non-empty path.
While you're here: stop counting requests
Related failure, same family:
cy.wait(['@layout', '@layout', '@layout'])
Exact-count waits bake a request count into your test. The moment the app legitimately batches two calls into one, or adds a fourth, the spec fails and tells you nothing useful. They're also unstable across environments where caching differs.
One wait plus a retriable assertion on the end state does the same job and survives refactors. Where you genuinely need "all in-flight work settled", wrap it in a named helper, so there's one place to fix when the app's request pattern changes.
The one-minute triage
Here's the minute I promised:
| What you see | Cause | Fix |
|---|---|---|
| Request visible in command log, wait on a narrow alias fails | Aliased after the trigger | Helper owns the trigger |
| Request visible, wait on a shared/broad alias fails | A later handler ended the chain | req.on('before:response') |
| Passes once, then never again | Endpoint only fires on change | Relative input or fixture reset |
| First wait resolves, second times out; response was 204 | Hand-off with no result event | Wait on the ack plus the UI end state |
That minute is cheaper than any cy.wait(2000). And the result is real: making the shared helpers own their trigger took a whole family of intermittent failures across unrelated specs out in a single commit.
Happy testing!
