Skip to content

Cypress Wait Alias Timeout Exceeded Fix

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about Cypress Wait Alias Timeout Exceeded Fix. We cover key concepts, practical examples, and best practices.

Your cy.wait('@alias') times out — the request never happened, or the alias wasn't registered in time.

The Problem

// WRONG — alias registered after request
cy.visit('/dashboard');
cy.intercept('GET', '/api/data').as('getData');
cy.wait('@getData'); // Timeout — request already sent

The page fires the API request during load. The intercept is registered after the request already completed.

Step-by-Step Fix

1. Register alias before navigation

// RIGHT — intercept before visit
cy.intercept('GET', '/api/data').as('getData');
cy.visit('/dashboard');
cy.wait('@getData');

2. Wait for multiple requests

// RIGHT — wait for multiple aliases
cy.intercept('GET', '/api/users').as('getUsers');
cy.intercept('GET', '/api/settings').as('getSettings');

cy.visit('/dashboard');

cy.wait(['"@getUsers"', '"@getSettings"']);

3. Access request properties after wait

// RIGHT — inspect intercepted request
cy.intercept('POST', '/api/users').as('createUser');

cy.get('button').click();

cy.wait('@createUser').then((interception) => {
  expect(interception.response.statusCode).to.equal(201);
  expect(interception.request.body).to.have.property('name');
});

4. Handle optional requests

// RIGHT — wait with timeout for optional requests
cy.intercept('GET', '/api/optional').as('getOptional');

// Wait but don't fail if request doesn't happen
cy.wait('@getOptional', { timeout: 3000 }).then((interception) => {
  if (interception) {
    // Request happened
  } else {
    // Request didn't happen (timeout)
  }
});

Expected output:

  ✓ waits for API data
  ✓ waits for multiple requests
  ✓ inspects request properties

Prevention Tips

  • Register intercepts before navigation
  • Use array syntax for multiple waits
  • Access interception object for request/response details
  • Set appropriate timeouts for each wait
  • Use .then() after wait for response validation

Common Mistakes with wait aliases

  1. Mixing let bindings with <- bindings in do notation, producing type errors
  2. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  3. Non-exhaustive pattern matches that compile with warnings then crash at runtime

These mistakes appear frequently in real-world CYPRESS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### How do I wait for a request that may not happen?

Use cy.wait('@alias', { timeout: 5000 }) with a short timeout. Catch the timeout error or check if interception is null.

Can I wait for the Nth occurrence of a request?

Yes: cy.wait('@alias').then(...) waits for the first occurrence. Use .wait properties to count: cy.get('@alias.all').should('have.length', 3).

What's the difference between @alias and @alias.all?

@alias gives the latest interception. @alias.all is an array of all interceptions for that alias. Use .all when a request happens multiple times.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro