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.
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 :)
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