【发布时间】:2018-11-06 14:08:14
【问题描述】:
【问题讨论】:
标签: typescript cypress
【问题讨论】:
标签: typescript cypress
好的,我刚刚解决了。
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)
})
})
【讨论】:
也可以使用 chai expect 断言来完成,如下所示:
cy.wait('@signin').then((xhr) => {
expect(xhr.status).to.equal(401);
});
您可以阅读更多关于它的信息in cypress documentation for cy.wait()。他们的XHR Assertions examples github project 中也有大量示例。
【讨论】:
这是解决它的新方法:
cy.intercept(
{
method:'GET',
url:'/api/channels/e5932cce
}).as('loginLoaded')
cy.get("@loginLoaded").then((xhr) => {
cy.wait('@loginLoaded').its('response.statusCode').should('eq', 401)
})
【讨论】: