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的更多相关文章

  1. Cypress系列(5)- 自定义 Cypress

    如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 前言 Cypress 不仅支持用户自定义 ...

  2. [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 ...

  3. Cypress系列(4)- 解析 Cypress 的默认文件结构

    如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 默认文件结构 在使用 cypress o ...

  4. [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 ...

  5. [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 ...

  6. [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 ...

  7. [Cypress] Load Data from Test Fixtures in Cypress

    When creating integration tests with Cypress, we’ll often want to stub network requests that respond ...

  8. [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 ...

  9. 2015年iOS测试现状

    本文由 伯乐在线 - nathanw 翻译,dopcn 校稿.未经许可,禁止转载! 英文出处:www.mokacoding.com.欢迎加入翻译小组. 几周前,我决定将将我在 mokacoding 上 ...

随机推荐

  1. Section %post does not end with %end

    Section %post does not end with %end Exception AttributeError: "NoneType" object no attrib ...

  2. 快速排序及三向切分快排——java实现

    快速排序也是一种分治算法.主要思想是选取一个切分点,将大于切分点的元素都放置到数组右侧,小于切分点的元素都放置到数组左侧:然后递归,再对切分点左侧和右侧分别排序. 归并排序时递归在前,归并在后,快速排 ...

  3. 基于CGAL的Delaunay三角网应用

    目录 1. 背景 1.1 CGAL 1.2 cgal-bindings(Python包) 1.3 vtk-python 1.4 PyQt5 2. 功能设计 2.1 基本目标 2.2 待实现目标 3. ...

  4. 《CSS Mastery》 读书笔记 (1)

    --本笔记中英混合,专业名词尽量不翻译,免得误解,如果不习惯,就不用往下看了,走好不送. 第一章 基础 人类的好奇心总是促使我们捣鼓,捣鼓是最好做有效的学习CSS的方法 In this chapter ...

  5. 浅谈ByteBuffer转换成byte[]时遇到的问题

    有些时候我们要把ByteBuffer转换成byte[]来使用.于是很多时候会用以下代码来转换: ByteBuffer buf; .....(一些往buffer写数据的操作) byte[] bs= ne ...

  6. C# 连接 access2010数据库

    //定义一个新的OleDb连接 System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(); // ...

  7. 复习java基础第二天(异常处理)

    一.常见的异常类型: public class TestException { public static void main(String[] args) { int i = 10; //数学异常: ...

  8. css属性代码大全总结(一)

    一 CSS文字属性: color : #999999; /*文字颜色*/ font-family : 宋体,sans-serif; /*文字字体*/ font-size : 9pt; /*文字大小*/ ...

  9. Android:JAVA使用HDF5存储

    Hierarchical Data Format,可以存储不同类型的图像和数码数据的文件格式,并且可以在不同类型的机器上传输,同时还有统一处理这种文件格式的函数库.大多数普通计算机都支持这种文件格式. ...

  10. SLAM: 图像角点检测的Fast算法(OpenCV文档)

    官方链接:http://docs.opencv.org/trunk/doc/py_tutorials/py_feature2d/py_fast/py_fast.html#fast-algorithm- ...