标签:子函数 新建 serve uil pil 单元测试 虚拟 测试结果 any
Selenium工具自动打开浏览器测试suite()test()setup()teardown()describle()it()before()after()beforeEach()afterEach()mochatest目录下第一层的脚本--recursive会运行当前目录以及子目录的脚本mocha spec/{one,two}.js mocha test/unit/*.js mocha test/{,**/}*.{js,jsx}node通配符
mocha ‘test/**/*.@(js|jsx)‘
--help, -h: 查看所有命令参数--reporter, -R: 指定测试报告格式,官方详细介绍
spec: 默认格式tap: ``mochawesome: 以HTML格式报告mocha --recursive -R markdown > spec.mdmocha -recursive -R doc > spec.html--growl, -G: 测试结果在桌面显示--watch, -w: 监视指定测试脚本,有变化会自动运行mocha--bail, -b: 指定只要有一个测试没有通过,就停止执行后面的测试用例--grep, -g: 用于搜索测试用例的名称--invert, -i: 只运行不符合条件的测试脚本, 必须与--grep配合使用
mocha --grep "1 加 1" --invert
mocha --recursive --reporter tap --growlmocha.opts文件--reporter tap --recursive --growl指定测试目录mocha.opts文件
server-tests --recursive
npm i babel-polyfill --save npm i @babel/core @babel/preset-env -D.babelrc配置{ "presets": [ ["@babel/env", { "modules": false, "useBuiltIns": "usage", "corejs": 2, "shippedProposals": true }] ] }npx mocha --compilers js:@babel/core/registerCoffeScript
npx mocha --compilers coffee:coffee-script/register
it(‘延时1000毫秒‘, function(done) { setTimeout(() => { done() }, 1e3) }) it(‘请求之后执行‘, function() { request .get(‘https://api.github.com‘) .end(function(err, res) { expect(res).to.be.an(‘object‘) done() }) })it(‘请求之后执行‘, function() { return request .get(‘https://api.github.com‘) .end(function(err, res) { expect(res).to.be.an(‘object‘) }) })mocha -t 1000: 设置超时时间未1000毫秒mocha -s 1000: 设置测试延时1000毫秒执行beforeafterbeforeEachafterEachonly只运行某个用例
mocha init testadd.jsfunction add(x, y) { return x + y; }把add.js和chai.js加入index.html
```
新建tests.js
```
var expect = chai.expect;
describe(‘加法函数的测试‘, function() {
it(‘1 加 1 应该等于 2‘, function() {
expect(add(1, 1)).to.be.equal(2);
});
it('任何数加0等于自身', function() {
expect(add(1, 0)).to.be.equal(1);
expect(add(0, 0)).to.be.equal(0);
});
});
```
标签:子函数 新建 serve uil pil 单元测试 虚拟 测试结果 any
原文地址:https://www.cnblogs.com/muzi131313/p/11676849.html