I am trying to intercept a graphql mutation to access its response. Cypress doesn't notice the request and cy.wait() times out.
test
describe('/profile', () => {
beforeEach(() => {
cy.server()
cy.route({
method: 'POST',
url: Cypress.config().baseUrl + '/graphql',
}).as('graphql')
cy.fastLogin()
cy.visit('/profile')
})
it('is possible to change password', () => {
cy.get('[data-cy=change-password-btn]').click()
cy.get('[name=oldPassword]').type(Cypress.config().password)
cy.get('[name=newPassword]').type('password1')
cy.get('[name=confirmNewPassword]').type('password1')
cy.get('[data-cy=change-pw-form-btn]').click()
cy.wait('@graphql').then(xhr => {
cy.log(JSON.stringify(xhr.response.body))
})
cy.get('[data-cy=notification-container]').should(
'contain',
'Your password has been changed'
)
})
I found a common problem that many people were having was that they called cy.server() or cy.route() after cy.visit(). That's is not my case, but still the cy.wait() fails.
I have a NodeJS backend and ReactJS frontend if that makes any difference.
Any ideas?
fetch, maybe? See github.com/cypress-io/cypress/issues/95 - jonrsharpefetch. So that is whycypressdidn't see them. I used this gist: gist.github.com/yagudaev/2ad1ef4a21a2d1cfe0e7d96afc7170bc to tranformfetchtoxhrin my tests. Now I can see the queries incypress, but thecy.wait()call still times out. - slinden