This test stubs the GET /api/users call to return two users. Then it visits the users page and checks that two user names appear, with the first being 'Alice'.
B. The HTTP method 'POST' is invalid in cy.intercept
C. The response body must be a string, not an object
D. The alias '@loginRequest' is missing because the intercept was not aliased
Solution
Step 1: Check alias usage
The intercept is defined but not given an alias using .as(), so '@loginRequest' does not exist.
Step 2: Understand wait on alias
Waiting on '@loginRequest' fails because the alias was never created.
Final Answer:
The alias '@loginRequest' is missing because the intercept was not aliased -> Option D
Quick Check:
Alias missing causes wait failure [OK]
Hint: Always alias intercept with .as() before waiting [OK]
Common Mistakes:
Forgetting to add .as() to intercept
Thinking POST is invalid method
Believing response body must be string
5. You want to stub a GET request to '/products' that returns different responses based on a query parameter 'category'. Which is the best way to implement this in Cypress?
hard
A. Create multiple cy.intercept calls with the same URL but different responses
B. Use cy.intercept with a function handler to check req.query.category and send different responses
C. Use cy.intercept with a static response ignoring query parameters
D. Use cy.route with a fixture file for all categories
Solution
Step 1: Understand dynamic stubbing need
Different responses based on query parameters require conditional logic in the stub.
Step 2: Use function handler in cy.intercept
cy.intercept supports a function to inspect the request and send custom responses based on req.query.category.
Final Answer:
Use cy.intercept with a function handler to check req.query.category and send different responses -> Option B
Quick Check:
Function handler enables dynamic stubbing [OK]
Hint: Use function in cy.intercept for dynamic responses [OK]
Common Mistakes:
Trying multiple intercepts with same URL (only last applies)
Ignoring query parameters in stub
Using deprecated cy.route instead of cy.intercept
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.