0

I can't 'catch' requests to BE with Cypress. And even more, I can't see some XHR requests to BE, but they are in DevTools. I've added a screenshot with arrows to describe the problem better. enter image description here

I can't upload my project to the public repo, but maybe you can get some ideas based on the test itself. I don't have any beforeEach, etc.

it('should generate the right request for password change', () => { cy.visit(`/courses/reset-password?token=${token}&userId=${userId}`); cy.server(); cy.route('POST', '/auth/local/reset-password').as('resetRequest'); cy.get('#password').type(password); cy.get('#confirmPassword').type(password); cy.get('button[type="submit"]').click(); console.log('at the end'); cy.wait('@resetRequest').then((request) => { // never get here console.log('fff', request); console.log('requestBody', request.requestBody); expect(request.body.newPassword).to.eq(password); expect(request.body.token).to.eq(token); expect(request.body.userId).to.eq(userId); }); 

});

If anyone has any ideas - please share them with me :)

2
  • 1
    Specifying the URL as a string in cy.route() can be tricky. See docs.cypress.io/api/commands/route.html#url-as-a-string. Try using a glob pattern or regex instead. Also, make sure it's really an XHR and not a fetch. Cypress doesn't see fetch requests. Commented Apr 16, 2020 at 2:18
  • @PeaceAndQuiet and is there any way to get 'fetch' or I should always rewrite 'fetch' to xhr to use cypress ? because I'm using fetch :( Commented Apr 16, 2020 at 19:32

2 Answers 2

2

To be able to use cy.server() & cy.route() with fetch requests, you need to do as stated here: https://stackoverflow.com/a/49088084/9947826

Sign up to request clarification or add additional context in comments.

Comments

0

I happened to find this code below, and worked fine on my end. Fetch calls are now displayed as XHR requests on the test logs.

Cypress.on("window:before:load", win => { win.fetch = null; }); 

Source: https://github.com/cypress-io/cypress/issues/95#issuecomment-347607198

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.