0
0
Cypresstesting~10 mins

Fixture-based response mocking in Cypress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load a fixture file named 'user.json' before the test.

Cypress
cy.fixture([1]).then((user) => { cy.log(user.name) })
Drag options to blanks, or click blank then click option'
A'user'
B'user.json'
Cuser.json
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the fixture file name
Omitting the .json extension
2fill in blank
medium

Complete the code to intercept a GET request to '/api/user' and respond with fixture data.

Cypress
cy.intercept('GET', '/api/user', { fixture: [1] }).as('getUser')
Drag options to blanks, or click blank then click option'
A'user.json'
B'userData'
Cuser
D'user'
Attempts:
3 left
💡 Hint
Common Mistakes
Including the .json extension in the fixture name
Not using quotes around the fixture name
3fill in blank
hard

Fix the error in the code to wait for the intercepted request alias 'getUser'.

Cypress
cy.wait([1])
Drag options to blanks, or click blank then click option'
A'@getUser'
B'getUser'
CgetUser
D@getUser
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the '@' symbol before the alias
Not using quotes around the alias
4fill in blank
hard

Fill both blanks to intercept a POST request to '/api/login' and respond with fixture 'loginResponse'.

Cypress
cy.intercept([1], [2], { fixture: 'loginResponse' }).as('postLogin')
Drag options to blanks, or click blank then click option'
A'POST'
B'/api/login'
C'GET'
D'/api/user'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'GET' instead of 'POST' for the method
Using wrong URL path in the intercept
5fill in blank
hard

Fill all three blanks to load fixture 'profile', intercept GET '/api/profile', and wait for the alias.

Cypress
cy.fixture([1]).then((profile) => {
  cy.intercept([2], { fixture: profile }).as('getProfile')
  cy.wait([3])
})
Drag options to blanks, or click blank then click option'
A'profile.json'
B'GET'
C'@getProfile'
D'/api/profile'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting .json in fixture file name
Using URL instead of method in intercept
Not using '@' in wait alias