assert(value[, message])
assert.ok(value[, message])
assert()是assert.ok()的简写方式,二者用法同样。
若是value的值为true,那么什么也不会发生。若是value为false,将抛出一个信息为message的错误。
assert.equal(actual, expected[, message])
判断实际值(actual)与指望徝(expected)是否相等(==),若是不相等,则抛出一个message的错误。
assert.deepEqual(actual, expected[, message])
deep意味着子对象的可枚举属性也会被计算进去。若是自己属性及子对象属性都相等时经过。不然会抛出错误。
assert.deepStrictEqual(actual, expected[, message])
判断条件为是否深度严格相等。
assert.notDeepEqual(actual, expected[, message])
assert.notDeepStrictEqual(actual, expected[, message])
assert.notEqual(actual, expected[, message])
assert.notStrictEqual(actual, expected[, message])
assert.strictEqual(actual, expected[, message])
assert.throws(block[, error][, message])复制代码
should.js
了解部分,基本写法以下:html
.true (===)node
true.should.be.true;复制代码
.false (!==)npm
false.should.be.false
(0).should.not.be.false复制代码
参考文档 https://unitjs.com/guide/should-js.html
bash
mocha
安装ide
npm install mocha -g复制代码
参考文档 http://www.ruanyifeng.com/blog/2015/12/a-mocha-tutorial-of-examples.html
测试
karma
npm install karma -D复制代码
karma配置 初始化测试 $ karma init (按照提示下一步下一步结束后会生产配置文件:karma.conf.js)ui
1. Which testing framework do you want to use ? (mocha) spa
2. Do you want to use Require.js ? (no) .net
3. Do you want to capture any browsers automatically ? (Chrome) code
4. What is the location of your source and test files ? (test/**.js)
5. Should any of the files included by the previous patterns be excluded ? ()
6. Do you want Karma to watch all the files and run the tests on change ? (yes)
参考文章 https://blog.csdn.net/wknhsj1/article/details/79243385
Travis CI
官网https://travis-ci.org/
.travis.yml
node 项目准备
language: node_js
node_js:
- "8"复制代码
运行
npm i
npm test复制代码
参考文章 http://www.ruanyifeng.com/blog/2017/12/travis_ci_tutorial.html