Reputation: 169
I am trying to stub a response from an API. Following the Cypress docs, I landed on this:
cy.intercept('GET', '/v1/answers', { fixture: 'answers.json' }).as(
'getAnswers'
)
cy.wait('@getAnswers').then(console.log)
The console.log
yields the correct response.
However the UI component does not appear to consume this data. Instead the data in the component comes back as empty. Is there something I am missing on the correct usage of intercept and fixtures in Cypress?
Upvotes: 2
Views: 3246
Reputation: 169
For anyone having this issue. In the Cypress app's browser console I noticed a CORS error and needed to add Access-Control-Allow-Origin
.
cy.intercept('GET', '/v1/answers', {
fixture: 'answers.json',
headers: {
'Access-Control-Allow-Origin': '*', // <== This fixed it
},
}).as('getAnswers')
:)
Upvotes: 2