[Cypress] Test XHR Failure Conditions with Cypress
Posted Answer1215
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Cypress] Test XHR Failure Conditions with Cypress相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章
配置 Cypress、cypress-react-unit-test 和 React
[Cypress] Test React’s Controlled Input with Cypress Selector Playground
[Cypress] Create True end-to-end Tests with Cypress (Smoke test)