码迷,mamicode.com
首页 > 其他好文 > 详细

[Cypress] Test XHR Failure Conditions with Cypress

时间:2018-05-26 23:28:15      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:ati   EDA   route   mes   func   dos   cal   front   new   

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

标签:ati   EDA   route   mes   func   dos   cal   front   new   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!