Cypress · Junior · Question 31 of 75
How do you stub an API response with fixed data?
- 1
cy.intercept('GET', '/api/users', { fixture: 'users.json' }) - 2
cy.request('GET', '/api/users').returns('users.json') - 3
cy.mock('GET', '/api/users', { file: 'users.json' })
Show the answer
Correct answer: cy.intercept('GET', '/api/users', { fixture: 'users.json' })
Explanation
A static response or fixture replaces the real server answer, making tests fast and deterministic.