Typescript 如何验证POST xhr

Typescript 如何验证POST xhr,typescript,cypress,Typescript,Cypress,我如何验证此xhr post是否被中止(在这种情况下,它应该是积极的场景,测试应该通过?好的,我刚刚解决了它 description('寄存器',函数()){ 它('步骤0',函数(){ cy.visit('localhost:4200') }) it('电子邮件验证',函数(){ cy.server(); cy.route('POST','**签到')。作为('sign'); cy.get('[data cy=“signup input”]')。类型('test@test.pl') cy.g

我如何验证此xhr post是否被中止(在这种情况下,它应该是积极的场景,测试应该通过?

好的,我刚刚解决了它

description('寄存器',函数()){
它('步骤0',函数(){
cy.visit('localhost:4200')
})
it('电子邮件验证',函数(){
cy.server();
cy.route('POST','**签到')。作为('sign');
cy.get('[data cy=“signup input”]')。类型('test@test.pl')
cy.get('[data cy=input password]')。类型('test123456{enter}'))
cy.get('[data cy=“email-error1”]')。应该('be.visible')
cy.wait('@sign')。其('status')。应('equal',401)
})

})
也可以使用如下断言:

cy.wait('@signin').then((xhr) => {
    expect(xhr.status).to.equal(401);
});

你可以阅读更多关于它的内容。他们的文章中也有大量的例子。

这是解决这个问题的新方法:

  cy.intercept(
    {
    method:'GET',
    url:'/api/channels/e5932cce
    }).as('loginLoaded')
 
  cy.get("@loginLoaded").then((xhr) => {
    cy.wait('@loginLoaded').its('response.statusCode').should('eq', 401)
    })