首页 > 其他 > 详细

[Cypress] Test XHR Failure Conditions with Cypress

时间:2018-05-26 23:12:40      阅读:278      评论:0      收藏:0      [点我收藏+]

Testing your application’s behavior when an XHR call results in an error can be difficult. The use of stubs for XHR calls makes it easy for us to setup failure scenarios and ensure that our front-end responds the way we expect. In this lesson, we’ll stub a 500 response for a form submission and verify that our application responds appropriately.

 

    it(‘should show an error message for a failed from subission‘, function () {
        const newTodo = "Test";
        cy.server();
        cy.route({
            method: ‘POST‘,
            url: ‘/api/todos‘,
            status: 500,
            response: {}
        }).as(‘save‘);

        cy.seedAndVisit();

        cy.get(‘.new-todo‘)
            .type(newTodo)
            .type(‘{enter}‘);

        cy.wait(‘@save‘);

        cy.get(‘.todo-list li‘).should(‘have.length‘, 4);
        cy.get(‘.error‘).should(‘be.visible‘);
    });

技术分享图片

[Cypress] Test XHR Failure Conditions with Cypress

原文:https://www.cnblogs.com/Answer1215/p/9094634.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!