node assert/should.js/mocha/karma/Travis CI预习

147 阅读1分钟
node assert部分方法

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

 了解部分,基本写法如下:

.true (===)

true.should.be.true;

.false (!==)

false.should.be.false
(0).should.not.be.false

参考文档 https://unitjs.com/guide/should-js.html


mocha

安装

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)

 1. Which testing framework do you want to use ? (mocha) 

2. Do you want to use Require.js ? (no) 

3. Do you want to capture any browsers automatically ? (Chrome) 

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