'Cypress - Waiting on canceled XHR Request

I have the intended functionality of canceling a pending XHR request in the application. I want to verify that the request is canceled after invoking the cancel action.

Right now I have this:

cy.intercept('GET', '**/request/**').as('Request');
invokeRequest();
invokeCancel();
cy.wait('@Request');

However, cypress is timing out on the cy.wait(). Is there a way to verify the request has been canceled?



Solution 1:[1]

You can use should and validate

it('should use wait value', () => {
  cy.intercept('/todos').as('todos')
  cy.visit('/')
  cy.wait('@todos').should('include.all.keys', ['request', 'response'])
})

else you can use cy.route() instead of cy.intercept(). Refer this Has lot of examples: https://glebbahmutov.com/blog/cypress-intercept-problems/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Umesh Sulakude