Ext*_*mer 0 html javascript unit-testing vue.js cypress
我使用 Cypress 和 Cucumber 来使用行为驱动开发 (BDD) 来开发带有 vue.js 的前端。我已经可以使用 Cypress 进行端到端测试,但我还需要创建和运行单元测试。我在 Cypress 官方网站上找不到任何内容。如何为此前端创建和运行单元测试?
您可以在官方文档中找到与单元测试相关的所有食谱。
假设您想从应用程序的代码中对数学函数进行单元测试,您可以使用 Cypress 来实现:
/// <reference types="cypress" />
import math from '../../math'
describe('Unit Test Application Code', function () {
const { add, divide, multiply, subtract } = math
before(() => {
// check if the import worked correctly
expect(add, 'add').to.be.a('function')
})
context('math.js', function () {
it('can add numbers', function () {
expect(add(1, 2)).to.eq(3)
})
it('can subtract numbers', function () {
expect(subtract(5, 12)).to.eq(-7)
})
it('can divide numbers', function () {
expect(divide(27, 9)).to.eq(3)
})
it('can muliple numbers', function () {
expect(multiply(5, 4)).to.eq(20)
})
})
})
Run Code Online (Sandbox Code Playgroud)