When creating integration tests with Cypress, we’ll often want to stub network requests that respond with large datasets. All of this mock data can lead to test code that is hard to read. In this lesson, we’ll see how to use fixtures to keep sample data in files and easily load it on demand in your tests.

Now we hard code the mock data into the test, somehow, we want those data can be reuseable for other cases.

So we need to change the following implementation by using fixture:

    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);
});

Add cypress/fixtures/todos.json:

[
{ "id": 1, "name": "One", "isComplete": false },
{ "id": 2, "name": "Two", "isComplete": false },
{ "id": 3, "name": "Three", "isComplete": false },
{ "id": 4, "name": "Four", "isComplete": false }
]

Then change our code to:

    it('should have four initial todos', function () {
cy.server();
cy.fixture('todos')
.then(todos => {
cy.route('GET', '/api/todos', todos);
}); cy.visit('/'); cy.get('.todo-list > li')
.should('have.length', 4);
});

There is a simple way provided by Cypress:

    it('should have four initial todos', function () {
cy.server();
/*
cy.fixture('todos')
.then(todos => {
cy.route('GET', '/api/todos', todos);
});
*/
cy.route('GET', '/api/todos', 'fixture:todos');
cy.visit('/'); cy.get('.todo-list > li')
.should('have.length', 4);
});

[Cypress] Load Data from Test Fixtures in Cypress的更多相关文章

  1. mysql load data 乱码

    解决方案: http://stackoverflow.com/questions/26256421/sql-load-data-infile-utf8-issue 即: load data local ...

  2. Mybatis拦截器 mysql load data local 内存流处理

    Mybatis 拦截器不做解释了,用过的基本都知道,这里用load data local主要是应对大批量数据的处理,提高性能,也支持事务回滚,且不影响其他的DML操作,当然这个操作不要涉及到当前所lo ...

  3. mysql load data 乱码的问题

    新学mysql在用load data导入txt文档时发现导入的内容,select 之后是乱码,先后把表,数据库的字符集类型修改为utf8,但还是一样,最后在 http://bbs.chinaunix. ...

  4. mysql load data infile的使用 和 SELECT into outfile备份数据库数据

    LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name.txt' [REPLACE | IGNORE] INTO TABLE t ...

  5. 快速的mysql导入导出数据(load data和outfile)

    1.load data: ***实际应用:把日志生成的xls文件load到MySQL中: mysql_cmd = "iconv -c -f utf-8 -t gbk ./data/al_ve ...

  6. 记录load data infile 的用法

    load data local infile 'd:/1.txt' into table tcm.wm_dis_category fields terminated by';' lines termi ...

  7. [MySQL]load data local infile向MySQL数据库中导入数据时,无法导入和字段不分离问题。

    利用load data将文件中的数据导入数据库表中的时候,遇到了两个问题. 首先是load data命令无法执行的问题: 命令行下输入load data local infile "path ...

  8. load data ERROR 1197 (HY000)错误

    有一份csv格式的文件,大小在14G左右.max_binlog_cache_size=4G. 登录mysql实例,选择对应的表通过load data往指定表里导数.大概20分钟左右,报以下错误: ER ...

  9. 批量导数据之利器-load data[2016-07-11]

    由于天热,中午吃完饭后不再去逛了,感觉这段时间其实也是可以利用起来的,所以决定每天中午积累一些小的知识点.今天中午,先总结一下最近造数据用到手命令,load data. 使用这个命令的起源是因为最近要 ...

随机推荐

  1. operator[] 重载

    #include <iostream>#include <vector>#include <string> class Assoc {    struct Pair ...

  2. css定位、position与float同时使用的情况

    一.css定位 CSS 有三种基本的定位机制:普通流.浮动和绝对定位. 1.普通流:未专门指定的元素都在普通流中定位,position:static/relative;和float:none;也在普通 ...

  3. IP Address

    http://poj.org/problem?id=2105 #include<stdio.h> #include<string.h> int main() { ]; ] = ...

  4. Servlet初始化与异步支持

    Shared libraries(共享库) / runtimes pluggability(运行时插件能力) 1.Servlet容器启动会扫描,当前应用里面每一个jar包的 ServletContai ...

  5. windows服务安装错误 在‘安装’过程发生异常:System.ComponentModel.Win32Exception:系统正在关机

    今天安装windows服务的时候先是在本地安装测试通过,但是一到服务器就一直安装失败 在‘安装’过程发生异常:System.ComponentModel.Win32Exception:系统正在关机 然 ...

  6. 在命令提示符窗口下(cmd)使用指令操作并编译java代码,运行java编译代码

    使用cmd操作java代码,编译.java文件,运行.class文件. 操作步骤: 1:创建一个文件夹: 例如:在e盘根目录(\)下面创建一个名为Hello的文件夹: 使用md指令:如图 在e盘中会生 ...

  7. 【Oracle】进入sqlplus 删除键backspace时出现^H

    当oracle进入sqlplus后,输入命令时候出现错误,我们按平时的习惯使用backspace键删除错误信息,此时会出现^H 解决办法:进入sqlplus之前,使用stty erase '^H'命令 ...

  8. yar 调用rpc方法

    <?php class RpcController extends Yaf_Controller_Abstract { //RPC入口 public function indexAction($ ...

  9. http 请求头示例

      POST /3-0/app/account/item HTTP/1.1 Host 10.100.138.32:8046 Content-Type application/json Accept-E ...

  10. C# 从小到大排列

    "; ; var ss = ""; ;i<str.Length;i++) { var s0 = str[i].ToString(); var s1 = (js).T ...