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. C# 单例3种写法

    public class Singleton { private static Singleton _instance = null; private Singleton(){} public sta ...

  2. Nginx 配置https请求

    通过阿里云生成指定的https证书文件xxxx.key 和 xxxx.pem文件 在阿里云上申请的https证书的是pem格式,转成cer 先在终端cd到文件目录下 然后 openssl x509 - ...

  3. 关于linux下的.a文件与 .so 文件

    连续几天终于将一个又一个问题解决了,这里说其中一个问题 描述问题:使用多线程pthread的时候,(我用的IDE,CODEBOLCKS)编译后发现直接弹出窗口,程序还没有被Build..巴拉巴拉,然后 ...

  4. Windows键盘驱动结构与消息机制--转

    https://www.douban.com/note/318793892/ 本文主要介绍按键消息是如何传递到窗口并转化为具体的按键消息的. Windows系统是事件驱动的多任务系统,其中按键和鼠标是 ...

  5. 实现一个类似于收趣APP的功能

    近日想做一个类似于收趣APP软件的一个功能,将头条.微信等其他App的文章能够通过分享微信好友的方式分享到自己的平台软件中. 分享的方式有三种: 1.通过微信好友的方式,将文章分享给收趣. 2.复制文 ...

  6. 前端开发之旅-zopim在线即时聊天客服

    一.与潜在客户实时聊天的神奇-zopim Zopim是一款高效的可嵌入网页中去的即使通讯与网站访客信息追踪的的Web软件.知道谁在访问您的网站吗?想和他们实时交流吗?想更有效的把握商机吗?使用Zopi ...

  7. Miller Rabin 大素数测试

    PS:本人第一次写随笔,写的不好请见谅. 接触MillerRabin算法大概是一年前,看到这个算法首先得为它的神奇之处大为赞叹,竟然可以通过几次随机数据的猜测就能判断出这数是否是素数,虽然说是有误差率 ...

  8. VC++ 遍历文件夹

    }; strcpy_s(szFind, MAX_PATH, m_szDir); strcat_s(szFind, "\\*.*"); WIN32_FIND_DATA wfd; HA ...

  9. Nginx 监控

    编译安装加上http_stub_status_module 模块 location /status { stub_status on; # access_log /usr/local/nginx/lo ...

  10. 【centOS7】Jenkins安装--漫漫踩坑路

    安装步骤: https://www.cnblogs.com/h--d/p/5673085.html 安装后遇到的问题及解决办法: jenkins的admin用户的初始密码路径 https://blog ...