Write test cases
We would like to use mocha to write our test cases.
- Install mocha
- Use
var assert = require('assert');
- Example of assert
It seems that we have just described a thing using English. Yes, what we are going to do is to describe what the functions in “node-validators” would works like.
Following the examples above, here comes the prototype of our use cases:
var assert = require('assert');
var validator = require('validator-test');
describe('Validator', function () {
describe('#isEmail', function () {
if (validator.isEmail('foo@bar.net') !== true) {
throw new Erorr('Validator not right');
}
});
});
The we will get the result:
Validator
#isEmail
✓ should return true when the string is an email address
1 passing (6ms)
What’s next? Just write test cases for every functions in “node-validator” in order to cover all.