博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Cypress] Stub a Post Request for Successful Form Submission with Cypress
阅读量:5294 次
发布时间:2019-06-14

本文共 1253 字,大约阅读时间需要 4 分钟。

In this lesson well stub a POST request and use Cypress commands to fill in and submit a form. We’ll wait for the submission to resolve and then assert that the new item was added to the list.

 

For example when we dealing with Form submition, we want to issue a new POST request and then check it should update number of todos.

 

it.only('should post new todo to the backend', function () {        // Serve the page        cy.server();        // Prepare a POST request        cy.route({            method: 'POST',            url: '/api/todos',            response: {id: 123, name: 'new todo', isComplete: false}        }).as('save');        // Call a custom command to load initial todos        cy.seedAndVisit();        // Enter a new todo        cy.get('.new-todo')            .type('new todo')            .type('{enter}');        // Wait network request to be finished        cy.wait('@save');        // Calculate the expected length of todos        cy.get('.todo-list li')            .should('have.length', 5);    });// commandCypress.Commands.add('seedAndVisit', (seedData = 'fixture:todos') => {  cy.server()  cy.route('GET', '/api/todos', seedData).as('load')  cy.visit('/')  cy.wait('@load')});

 

转载于:https://www.cnblogs.com/Answer1215/p/9094594.html

你可能感兴趣的文章
苹果手表:大方向和谷歌一样,硬件分道扬镳
查看>>
Competing Consumers Pattern (竞争消费者模式)
查看>>
HDUOJ ------1398
查看>>
cf--------(div1)1A. Theatre Square
查看>>
Android面试收集录15 Android Bitmap压缩策略
查看>>
PHP魔术方法之__call与__callStatic方法
查看>>
ubuntu 安装后的配置
查看>>
Html学习_简易个人网页制作
查看>>
jqery总结
查看>>
VSCODE更改文件时,提示:EACCES: permission denied的解决办法(mac电脑系统)
查看>>
web前端之路,js的一些好书(摘自聂微东 )
查看>>
【模板】对拍程序
查看>>
dos批处理(bat)运行exe
查看>>
Pycharm安装Markdown插件
查看>>
【转】redo与undo
查看>>
C#更新程序设计
查看>>
解决升级系统导致的 curl: (48) An unknown option was passed in to libcurl
查看>>
Shell命令-内置命令及其它之watch、date
查看>>
Java Session 介绍;
查看>>
spoj TBATTLE 质因数分解+二分
查看>>