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. 服务器上oracle的监听设置

    1.查看本机的计算机名 2.修改etc/host 3.修改oracle的listener.ora(我服务器上的路径:) 4.修改tnsnames.ora(和上边文件一个目录)

  2. Spring Web MVC核心架构

    可以查看DispatherServlet中的源代码,就是doDispatch()方法!

  3. 【Leetcode 166】 Fraction to Recurring Decimal

    Description: Given two integers representing the numerator and denominator of a fraction, return the ...

  4. vue-clickoutside d

    js文件 export default { bind(el, binding, vnode) { function documentHandler(e) { if (el.contains(e.tar ...

  5. Android Studio查看CPU使用率。

    进入AS自带的CMD,依次输入: (1)进入Android Atudio安卓的目录: 1.H: 2.cd AndroidStudio\sdk\platform-tools (2)adb shell ( ...

  6. Robomongo 0.9.0 连接mongo数据库时,提示连接失败 的解决方案

    Robomongo 0.9.0 连接mongo数据库时,提示连接失败.(IP和端口号确定是对的) 基本注意点: 1.mongodb服务打开,打开时,指定端口号,默认为27017,使用默认值,则不用指定 ...

  7. SSH整合框架+mysql简单的实现

    SSH整合框架+mysql简单的实现 1. 框架整合原理: struts2整合Spring 两种: 一种struts2自己创建Action,自动装配Service : 一种 将Action交给Spri ...

  8. 如何利用Flashback Query 恢复误删除的数据

    网上有很多关于数据回复的文章,这里整理一篇供大家参考,希望能帮助的大家! 推荐一家即时通讯云服务商:www.yun2win.com,功能包含im即时通讯.实时音视频.电子白板.屏幕共享的多种融合通讯云 ...

  9. Flask 框架构建

    Flask 框架构建,目标构建成Django类似的结构 一. 先看看构建后的效果 # 第一次初始化 python manage.py db init # 生成数据库版本 python manage.p ...

  10. ionic下拉多项选择

    1.npm install ion-multi-picker --save 2.引入 import { MultiPickerModule } from 'ion-multi-picker'; imp ...