node assert/should.js/mocha/karma/Travis CI預習

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

 瞭解部分,基本寫法以下: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

相關文章
相關標籤/搜索