How to validate POST xhr

Viewed 158

)

How can I validate if this xhr post is aborted (in this case it should be positive scenario and test should pass?

3 Answers

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)


  })
})

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)
    })
Related