Cypress Wait Alias Timeout Exceeded Fix
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
- Mixing let bindings with <- bindings in do notation, producing type errors
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
- 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
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro