Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
development:testing:mocha:start [2014/09/30 01:25] – [Installation] don.lee | development:testing:mocha:start [2019/01/13 12:34] (current) – [Sinon JS] don.lee | ||
---|---|---|---|
Line 5: | Line 5: | ||
===== Installation ===== | ===== Installation ===== | ||
- | * install the mocha & should | + | * install the mocha & eslint-plugin-mocha |
< | < | ||
- | $ npm install -g mocha | + | $ npm install --save-dev |
- | $ npm install | + | $ npm install |
</ | </ | ||
* create test folder and put test case there | * create test folder and put test case there | ||
Line 15: | Line 15: | ||
$ mocha | $ mocha | ||
</ | </ | ||
+ | |||
+ | Edit the .eslintrc.json file to include the eslint-plugin-mocha plugins | ||
+ | < | ||
+ | { | ||
+ | ... | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | ... | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Using .only for exclusive test only ===== | ||
+ | |||
+ | Mocha has a feature that allows you to run tests exclusively by appending .only to a test-suite or a test-case. This feature is really helpful to debug a failing test, so you don’t have to execute all of your tests. After you have fixed your test and before committing the changes you have to remove .only to ensure all tests are executed on your build system. | ||
+ | |||
+ | This rule looks for every describe.only, | ||
+ | |||
+ | e.g. | ||
+ | < | ||
+ | describe(' | ||
+ | it.only(' | ||
+ | ... | ||
+ | }) | ||
+ | it.only(' | ||
+ | ... | ||
+ | }) | ||
+ | }) | ||
+ | </ | ||
+ | |||
+ | ===== prefer arrow function callbacks (mocha-aware) ===== | ||
+ | |||
+ | In ES6, we use arrow function a lot. But in Mocha, both describe and it callback should NOT use arrow function as the this will no longer refer to suite/test. | ||
+ | |||
+ | e.g. INCORRECT | ||
+ | < | ||
+ | describe(' | ||
+ | this.timeout(5000) | ||
+ | ... | ||
+ | }) | ||
+ | </ | ||
+ | |||
+ | CORRECT | ||
+ | < | ||
+ | describe(' | ||
+ | this.timeout(5000) | ||
+ | ... | ||
+ | }) | ||
+ | </ | ||
+ | |||
+ | ===== Sinon JS ===== | ||
+ | |||
+ | * [[development: | ||
===== Test Case ===== | ===== Test Case ===== | ||
- | http://jasmine.github.io/2.0/introduction.html | + | |
+ | * Reference | ||
+ | http://www.wekeroad.com/2012/ | ||