[Cypress] Stub a Post Request for Successful Form Submission with Cypress
for with post request Form Cypress
2023-09-14 09:00:50 时间
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); }); // command Cypress.Commands.add('seedAndVisit', (seedData = 'fixture:todos') => { cy.server() cy.route('GET', '/api/todos', seedData).as('load') cy.visit('/') cy.wait('@load') });
相关文章
- [Android Pro] 完美解决 No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
- 卡尔曼滤波—Simple Kalman Filter for 2D tracking with OpenCV
- Self referencing loop detected for property 'XXXXXX' with type
- Bag of Tricks for Image Classification with Convolutional Neural Networks论文笔记
- Universal Image Loader for Android 使用实例
- [Kotlin] Typecheck with 'is' keyword, 'as' keyword for assert type
- [React] Improve developer experience for accessing context with a custom React hook
- [Javascript] Create an Async Generator and Loop Through Generated Promises with "For Await Of" Loops
- [React Storybook] Get started with Storybook for React
- [SCSS] Write similar classes with the SCSS @for Control Directive
- [Typescript] Get full type safe for discriminatedUnion type with 'type' & 'subtype' (2 levels)
- [Typescript] Step 4. ESLint for Typescript
- [Webpack] Create Separate webpack Configs for Development and Production with webpack-merge
- [tmux] Share a tmux session for pair programming with ssh
- 【转】Python IDE for Eclipse
- 如何给SAP Cloud for Customer UI上的字段添加自定义校验逻辑
- 如何处理SAP gateway service使用过程中遇到的400 error - invalid key predicate type for guid
- FaceSDK 8.0 for Android
- Stimulsoft Reports.NET 2022.4.3 for WinForms
- 成功解决IndexError: index 0 is out of bounds for axis 1 with size 0
- 华为云PB级数据库GaussDB(for Redis)揭秘第九期:与HBase的对比
- 这是你没见过的MindSpore 2.0.0 for Windows GPU版
- async for的使用
- spring xml properties split with comma for list
- 解决No registered ‘MultiDeviceIteratorGetNextFromShard‘ OpKernel for GPU devices compatible with node
- MySQL数据库for CentOS7 yum安装、5.7.30编译安装和基础操作