Challenge - 5 Problems
Fixture Mocking Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the test result when mocking a GET request with fixture data?
Consider this Cypress test code that mocks a GET request to '/api/user' using a fixture named 'user.json'. What will be the output of the assertion?
Cypress
cy.intercept('GET', '/api/user', { fixture: 'user.json' }).as('getUser'); cy.visit('/profile'); cy.wait('@getUser').its('response.body').should('have.property', 'name', 'Alice');
Attempts:
2 left
💡 Hint
Fixtures provide static data to mock API responses in Cypress.
✗ Incorrect
The fixture 'user.json' contains the user data with the name 'Alice'. Cypress intercepts the GET request and returns this fixture data, so the assertion passes.
❓ assertion
intermediate2:00remaining
Which assertion correctly verifies the mocked response status code?
You have mocked a POST request with a fixture in Cypress. Which assertion correctly checks that the response status code is 201?
Cypress
cy.intercept('POST', '/api/create', { fixture: 'createResponse.json' }).as('createItem'); cy.visit('/create'); cy.wait('@createItem').then((interception) => { // Assertion here });
Attempts:
2 left
💡 Hint
Check the Cypress interception object properties for response status code.
✗ Incorrect
The correct property for the response status code in Cypress interception is 'response.statusCode'.
🔧 Debug
advanced2:00remaining
Why does the fixture-based mock not work as expected?
This Cypress test tries to mock a GET request with a fixture but the test fails because the real server response is received instead. What is the likely cause?
Cypress
cy.intercept('GET', '/api/data', { fixture: 'data.json' }); cy.visit('/dashboard'); cy.get('.data-item').should('have.length', 5);
Attempts:
2 left
💡 Hint
Check if the URL pattern in intercept matches the actual request URL exactly.
✗ Incorrect
If the intercept URL pattern does not match the actual request URL, Cypress will not mock the response and the real server response will be used.
❓ framework
advanced2:00remaining
How to dynamically modify fixture data before mocking response?
You want to use fixture data but change the 'id' field dynamically before returning it in the mock response. Which Cypress code snippet achieves this?
Attempts:
2 left
💡 Hint
Use cy.fixture() inside intercept callback to modify data before reply.
✗ Incorrect
Option B loads the fixture asynchronously, modifies the 'id', then replies with the modified data, which is the correct way.
🧠 Conceptual
expert2:00remaining
What is the main advantage of using fixture-based response mocking in Cypress tests?
Choose the best explanation for why fixture-based response mocking is used in Cypress testing.
Attempts:
2 left
💡 Hint
Think about test speed and reliability when avoiding real servers.
✗ Incorrect
Fixture-based mocking uses static data to avoid network delays and variability, making tests faster and more stable.