[Cypress] Stub Network Requests in a Cypress Test
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.
[Cypress] Stub Network Requests in a Cypress Test的更多相关文章
- Cypress系列(5)- 自定义 Cypress
如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 前言 Cypress 不仅支持用户自定义 ...
- [Cypress] Stub a Post Request for Successful Form Submission with Cypress
In this lesson well stub a POST request and use Cypress commands to fill in and submit a form. We’ll ...
- Cypress系列(4)- 解析 Cypress 的默认文件结构
如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 默认文件结构 在使用 cypress o ...
- [RxJS] Reactive Programming - Sharing network requests with shareReplay()
Currently we show three users in the list, it actually do three time network request, we can verfiy ...
- [Cypress] Create True end-to-end Tests with Cypress (Smoke test)
Integration tests let us keep our tests fast and reliable. They also allow us to test scenarios that ...
- [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 o ...
- [Cypress] Load Data from Test Fixtures in Cypress
When creating integration tests with Cypress, we’ll often want to stub network requests that respond ...
- [Cypress] install, configure, and script Cypress for JavaScript web applications -- part4
Load Data from Test Fixtures in Cypress When creating integration tests with Cypress, we’ll often wa ...
- 2015年iOS测试现状
本文由 伯乐在线 - nathanw 翻译,dopcn 校稿.未经许可,禁止转载! 英文出处:www.mokacoding.com.欢迎加入翻译小组. 几周前,我决定将将我在 mokacoding 上 ...
随机推荐
- 函数中的this的四种绑定形式
目录 this的默认绑定 this的隐式绑定 隐式绑定下,作为对象属性的函数,对于对象来说是独立的 在一串对象属性链中,this绑定的是最内层的对象 this的显式绑定:(call和bind方法) n ...
- go之切片
一.概念 关于切片 1.切片是对数组一个连续片段的引用,所以切片是一个引用类型 2.切片是数组一样可以索引,可以通过len函数获取切片的数据长度.(数组也可以通过len获取) 3.切片是一个长度可变的 ...
- C++中const用法
1.const和指针: 如果const出现在星号左边,表示被指物是常量:如果出现在星号右边,表示指针自身是常量:如果出现在星号两边,表示被指物和指针两者都是常量. char greet[] = “He ...
- java反射机制学习小结
之前一直对java的反射机制理解得很模糊,今天因为学习spring,所以花了些时间总算把它理顺了,记录一下 另外,推荐读读这篇文章,写的挺好的http://blog.csdn.net/woshixuy ...
- 3d数学 7 矩阵
7.1 矩阵-数学定义 在线性代数中, 矩阵就是以行和列形式组织的矩形数字块.矩阵是向量的数组. 7.1.1 矩阵的维度和记法 矩阵的维度被定义为它包含了多少行和多少列.一个\(r \times c\ ...
- BZOJ 4010 拓扑排序+heap
思路: 反向图求最大拓扑序 反向输出 //By SiriusRen #include <queue> #include <cstdio> #include <cstrin ...
- B - Is your horseshoe on the other hoof?
Problem description Valera the Horse is going to the party with friends. He has been following the f ...
- python--4、装饰器
装饰器(Decorator) 使用场景:为被装饰器装饰的函数增加功能,但又不希望修改函数的定义,即在代码运行期间动态增加功能. 装饰器更多的用于后期功能升级而不是编写新的代码.装饰器不光能装饰函数,也 ...
- Android Studio项目中有用文件与可忽略文件(初学者)
可通过Settings --> Version Control --> Ignored Files进行设置或察看: 支持指定文件或文件夹,也支持匹配模式. Android Studio 中 ...
- ui界面设计
UI即User Interface(用户界面)的简称,指对软件的人机交互.操作逻辑.界面美观的整体设计.好的UI设计不仅是让软件变得有个性有品位,还要让软件的操作变得舒适简单.自由,充分体现软件的定位 ...