Created
November 29, 2018 02:19
-
-
Save BCEvanFang/35a9e8e46990b10e56b38866dcfd1774 to your computer and use it in GitHub Desktop.
A simple mocha unit test example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // install test tools | |
| // npm install mocha chai --save | |
| /* | |
| add.js | |
| */ | |
| function add(x, y) { | |
| return x + y; | |
| } | |
| module.exports = add; | |
| /* | |
| add.test.js | |
| */ | |
| var add = require("./add.js") | |
| var expect = require("chai").expect; | |
| describe('Add function', () => { | |
| it('1 + 2 = 3', () => { | |
| expect(add(1, 2)).to.be.equal(3); | |
| }); | |
| }); | |
| // test command | |
| // mocha ./add.test.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment