Integration tests let us keep our tests fast and reliable. They also allow us to test scenarios that are hard to recreate in a full end-to-end setup. That being said, we should round out our test suite with some high-level smoke tests. In this lesson, we’ll create some tests that seed our data-source and avoid stubbing our network calls, allowing us to test all parts of the application while using known data to keep our tests flake-free.

describe('Smoke Tests', () => {

    // context is no difference with describe in functionality
context('No Todos', () => {
it('Adds a new todo', () => {
cy.server()
cy.route('POST', '/api/todos').as('save') cy.visit('/') cy
.get('.new-todo')
.type('New todo')
.type('{enter}') cy.wait('@save') cy.get('.todo-list li').should('have.length', ) })
}) });

Now we have post a new todo to the backend, it will pass the test.

But the problem is that, when you rerun the test again, it will faild, because now in the db, we have two todos.

Therefore, we need to clear the db everytime before we run the test:

describe('Smoke Tests', () => {
beforeEach(() => {
cy.request('DELETE', '/api/todos/all')
}) // context is no difference with describe in functionality
context('No Todos', () => {
it('Adds a new todo', () => {
cy.server()
cy.route('POST', '/api/todos').as('save') cy.visit('/') cy
.get('.new-todo')
.type('New todo')
.type('{enter}') cy.wait('@save') cy.get('.todo-list li').should('have.length', 1) })
})
})

Another example:

    context('With todos', () => {
beforeEach(() => {
cy.fixture('todos').then(todos => {
cy.request('POST', '/api/todos/bulkload', {todos})
}) cy.server()
cy.route('GET', '/api/todos').as('load') cy.visit('/') cy.wait('@load')
}) it('Deletes todos', () => {
cy.route('DELETE', '/api/todos/*').as('delete') cy
.get('.todo-list li')
.each($el => {
cy
.wrap($el)
.find('.destroy')
.invoke('show')
.click() cy.wait('@delete')
})
.should('not.exist')
})
})

About smoke test

[Cypress] Create True end-to-end Tests with Cypress (Smoke test)的更多相关文章

  1. Cypress系列(1)- Window下安装 Cypress 并打开

    如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 系统要求 Cypress 是一个被安装在 ...

  2. [Cypress] Create Aliases for DOM Elements in Cypress Tests

    We’ll often need to access the same DOM elements multiple times in one test. Your first instinct mig ...

  3. [Cypress] Create a Single Custom Cypress Command from Multiple Commands

    Cypress provides a straightforward API that allows you to define custom commands. In this lesson, we ...

  4. Cypress系列(44)- 命令行运行 Cypress

    如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 前言 前面也介绍过 Cypress 命令 ...

  5. [Cypress] install, configure, and script Cypress for JavaScript web applications -- part1

    Despite the fact that Cypress is an application that runs natively on your machine, you can install ...

  6. Cypress测试工具

    参考博客:  https://testerhome.com/articles/19035 最近一段时间学习了cypress的测试工具, 她是一个端到端的测试web工具. 环境准备 1.工具:vs co ...

  7. [Cypress] install, configure, and script Cypress for JavaScript web applications -- part3

    Use custom Cypress command for reusable assertions We’re duplicating quite a few commands between th ...

  8. [Cypress] install, configure, and script Cypress for JavaScript web applications -- part2

    Use Cypress to test user registration Let’s write a test to fill out our registration form. Because ...

  9. [Cypress] Get started with Cypress

    Adding Cypress to a project is a simple npm install away. We won’t need any global dependencies beyo ...

随机推荐

  1. 【HTML5】基于HTML5的高性能动画与游戏

    其实这篇文章类似版本早在12年就在网上各处出现了,也随着HTML5的兴起,HTML的新特性也是倍受开发者们追捧,自然相关HTML5的高性能动画与游戏的相关文章也是层出不穷的,笔者也是在12年接触的相关 ...

  2. Codeforces Round 411 Div.2 题解

    A Fake NP standard input/output s, MB Submit Add to favourites x3673 B -palindrome standard input/ou ...

  3. Codeforces 769C

    很久没有发题解,今天这题卡了下百度没看到相关题解,最后还是看了官方题解才找到原本思路的bug过的. 题意:给出一个二维迷宫,*表示墙,. 表示路,X表示起点,问一个长度为k的路径,从X出发并且回到X, ...

  4. ACM_最短网络(最小生成树)

    Problem Description: Farmer John has been elected mayor of his town! One of his campaign promises wa ...

  5. 关于GIT使用过程中遇到的问题

    npm构建,将所需要安装的依赖添加至package.json文件中,使用cnpm i进行安装 #拉去指定项目的默认分支: git pull http://username:password@gitla ...

  6. Mysql的事务、视图、索引、备份和恢复

    事务 事务是作为单个逻辑工作单元执行的一系列操作,一个逻辑工作单元必须具备四个属性.即:原子性.一致性.隔离性.持久性,这些特性通常简称为ACID.   原子性(Atomicity) 事务是不可分割的 ...

  7. 常用animation动画

    /*编辑动画名*/ animation-name: myDemo; /*动画持续时间*/ animation-duration: 6s; /*动画方向*/ /*reverse 反向*/ /*alter ...

  8. 3分钟看懂flex布局

    首先要有个容器,并设置display:flex;display:-webkit-flex;该容器有以下六个属性: 1 2 3 4 5 6 7 8 9 10 11 12 flex-direction ( ...

  9. Android视频截图

    本文介绍如何获取视频中某个时间点的数据 调用以下方法即可,特别注意,在获取图片时的参数单位为微秒,不是毫秒 如果错用了毫秒会一直获取第一帧的画面 /** * 获取某个时间点的帧图片 * * @para ...

  10. 网络中 ping 不通 路由表

    不管是在window还是在linux中,我们经常会遇到ping不通的问题. 这里的原因很多,比如不同的网段交换机做了一些限制等,这些问题是我们人工不能解决的. 但是,当你发现各自的网关是可以ping的 ...