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. android 从assets和res中读取文件(转)

    1. 相关文件夹介绍      在Android项目文件夹里面,主要的资源文件是放在res文件夹里面的.assets文件夹是存放不进行编译加工的原生文件,即该文件夹里面的文件不会像xml,java文件 ...

  2. E20170907-ts

    flash  vt. 使闪光,使闪烁; 拍出,发出(电报等); 〈口〉炫耀;          adj. 闪光的,闪耀的,一闪而过的; 浮华的; 庞大的;           n. 闪光; 闪光灯下摄 ...

  3. python 46 盒模型 与盒模型布局

    一:盒模型 1.  盒模型的概念 广义盒模型:文档中所有功能性及内容性标签,及文档中显示性标签 侠义盒模型:文档中以块级形式存在的标签(块级标签拥有盒模型100%特性且最常用) 盒模型组成:margi ...

  4. 2-bitmap

    在2.5亿个整数中找出不重复的整数,注,内存不足以容纳这2.5亿个整数. 思路: bitmap用一个bit来代表存在还是不存在,现在我们要判断重不重复,则需要三个状态:不存在,存在一个,存在多个.2b ...

  5. MemcachedClient 使用说明

    上一篇介绍了Memcached基本使用方法<Memcached使用手册>,下面介绍java如何操作memcached.使用的是java_memcached-release_2.6.6. 一 ...

  6. SEO之如何做301转向

    1.如果网站使用的是(Linux+Apache+MySQL+PHP)主机,可以使用.htaccess文件做301转向 比如把/index.html 301转向到http://www.xinlvtian ...

  7. RadioButtonList绑定后台的数据。

    在前台,放置一个 <td style="width: 650px;"><asp:RadioButtonList ID="RadioButtonList2 ...

  8. mysql主从不同步,提示更新找不到记录

    查看丛库状态show slave status\G 从库原文提示:Last_Error: Coordinator stopped because there were error(s) in the ...

  9. 【Linux】ubuntu中怪异的vi编辑器

    由于前几天一场windows系统的比特币勒索病毒,我下狠心装了Linux的ubuntu版本.可是今天在使用命令行中的vi编辑器时出现了怪异的现象:backspace不能删除,编辑模式回车随机出现字母. ...

  10. 【PLSQL】游标

    Oracle中的SQL在执行时需要分配一块内存区域,这块内存区域叫做上下文区. 上下文区中记录了SQL语句的处理信息,这些信息包括:查询返回的数据行.查询所处理的数据的行号.指向共享池中的已分析的SQ ...