How can I validate if this xhr post is aborted (in this case it should be positive scenario and test should pass?
How can I validate if this xhr post is aborted (in this case it should be positive scenario and test should pass?
Ok, I just solved it.
describe('Register', function() {
it('Step 0', function() {
cy.visit('localhost:4200')
})
it('Email validation', function() {
cy.server();
cy.route('POST', '**sign_in').as('signin');
cy.get('[data-cy="signup-input"]').type('test@test.pl')
cy.get('[data-cy=input-password]').type('test123456{enter}')
cy.get('[data-cy="email-error1"]').should('be.visible')
cy.wait('@signin').its('status').should('equal', 401)
})
})
Can also be done with chai expect assertions like so:
cy.wait('@signin').then((xhr) => {
expect(xhr.status).to.equal(401);
});
You can read more about it in cypress documentation for cy.wait(). They also have tonnes of examples in their XHR Assertions examples github project.
this is the new way to solve it:
cy.intercept(
{
method:'GET',
url:'/api/channels/e5932cce
}).as('loginLoaded')
cy.get("@loginLoaded").then((xhr) => {
cy.wait('@loginLoaded').its('response.statusCode').should('eq', 401)
})