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. IJ:Idea 常用代码

    ylbtech-IJ:Idea 常用代码 1.返回顶部 1. 1.JeePlus/代码生成器http://localhost:8081/a/login 2.manager/Java基础框架http:/ ...

  2. 两个向量之间的欧式距离及radial-basis-functions(RBF)

    template <class DataType1, class DataType2>double EuclideanDistance(std::vector<DataType1&g ...

  3. 2205 等差数列(dp)

    2205 等差数列  时间限制: 1 s  空间限制: 32000 KB  题目等级 : 钻石 Diamond     题目描述 Description 等差数列的定义是一个数列S,它满足了(S[i] ...

  4. 《疯狂Python讲义》重要笔记--变量

    一个Python解释器 接下来的旅程——你需要下载好Python,Python解释器通常放在 /usr/local/bin/python3.7 ; 在Unix系统的bash中输入 where pyth ...

  5. go之数组

    一.数组概念 go语言提供了数组类型的数据结构 数组是具有 [唯一类型] 的一组 [固定长度] 的数据项序列,这种类型可以是任意类型 二.数组声明 var variable_name [SIZE]va ...

  6. BZOJ 3681 线段树合并+网络流

    思路: 暴力建图有n*m条边 考虑怎么优化 (那就只能加个线段树了呗) 然后我就不会写了..... 抄了一波题解 //By SiriusRen #include <bits/stdc++.h&g ...

  7. POJ 1101 译文

    The Game 题意: Description One morning, you wake up and think: "I am such a good programmer. Why ...

  8. 在mac上截屏的几种方式

    方法 1: 对屏幕的一部分进行截图 按下Command+Shift+4   方法 2: 对整个屏幕进行截图 按下Command+Shift+3   方法 3: 把截图保存到粘贴板 按下Command+ ...

  9. 阿里巴巴矢量库IconFont__使用小录

    使用阿里巴巴矢量库方法虽然不难,但本人记性不好,遂在次记录几笔 阿里巴巴矢量库地址:http://www.iconfont.cn/plus 阿里巴巴矢量库图标好处: 1:图标矢量化 2:自己总结:ic ...

  10. Hotel 旅馆 题解(From luoguBlog)

    考试前深陷分块泥潭所以刚开始以为是分块. 然而这题数据水到暴力卡常都能AC 正解:万物皆可线段树 节点存储区间长度.区间最长连续空房长度.从左往右最长连续空房长度.从右往左最长连续空房长度. 维护后三 ...