博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Cypress] Stub Network Requests in a Cypress Test
阅读量:5090 次
发布时间:2019-06-13

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

To keep our tests fast and easily repeatable, it makes sense to create many integration tests and fewer full end-to-end tests. In this lesson, we’ll see how to stub out network requests to create repeatable integration tests by ensuring our application runs in a known state for our tests.

 

For example if we want to test for the initial loading, how many initial data should get.

If we get doing like this, it actually point to the server, everytime we add one or remove one will affect the testing results.

it('should have four initial todos', function () {        cy.get('.todo-list > li')            .should('have.length', 4);    });

 

We can mock and control what data we will get for the endpoint:

it('should have four initial todos', function () {        cy.server();        cy.route('GET', '/api/todos', [            {id: 1, name: 'one', isComplete: false},            {id: 2, name: 'two', isComplete: false},            {id: 3, name: 'three', isComplete: false},            {id: 4, name: 'four', isComplete: false}        ]);        cy.visit('/');        cy.get('.todo-list > li')            .should('have.length', 4);    });

So now no matter we add one or remove one todo from the list, each time tests run will have the same result.

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

你可能感兴趣的文章
【线性代数】3-2:零空间(Nullspace)
查看>>
Solr 03 - 解读Solr的schema.xml文件 (Solr的模式设计与优化)
查看>>
打靶射击[递归]
查看>>
QT5连接Mysql
查看>>
hadoop随手笔记
查看>>
【转】UML类图与类的关系详解
查看>>
单源最短路(bellman-ford算法+dijkstra算法)+任意两点最短路(floyd-warshall算法)...
查看>>
链表基本操作
查看>>
关于多线程的一个例子(UI实时显示)
查看>>
虔诚的IT探索者
查看>>
spring RoutingDataSource使用
查看>>
arcgis api 3.x for js 入门开发系列七图层控制(附源码下载)
查看>>
YTU 2878: 结构体--学生信息排序
查看>>
走进AngularJs 表单及表单验证
查看>>
nexus 7 2013 驱动安装及root
查看>>
如何从禁止拷贝的pdf中取出文本
查看>>
【转】Java检测字符串是否有乱码
查看>>
文件归档和压缩
查看>>
Git常用命令总结
查看>>
如何科学的决策!
查看>>