First install the testing framework:
npm install mocha --save-dev
npm install chai --save-dev
npm install mocha -g
Then at the top of the spec file:
var expect = require('chai').expect;
//pull in whatever module/functions we are testing.
var pingpong = require('./../js/pingpong.js').pingpong;
Now we can run tests with:
mocha [name of spec folder]
For example, let's assume our test files are in a folder called spec. Then the command would be:
mocha spec
And we should throw the command into our package.json file. Find the line that starts with "test" :
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
And replace it with the testing command:
"scripts": {
"test": "mocha [name of spec folder]"
},
So with a test folder called spec this would be:
"scripts": {
"test": "mocha spec"
},
Then from the command line we can now run:
npm test