Write test cases

    We would like to use mocha to write our test cases.

    • Install mocha
    • Use
    1. 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:

    1. var assert = require('assert');
    2. var validator = require('validator-test');
    3. describe('Validator', function () {
    4. describe('#isEmail', function () {
    5. if (validator.isEmail('foo@bar.net') !== true) {
    6. throw new Erorr('Validator not right');
    7. }
    8. });
    9. });

    The we will get the result:

    1. Validator
    2. #isEmail
    3. should return true when the string is an email address
    4. 1 passing (6ms)

    What’s next? Just write test cases for every functions in “node-validator” in order to cover all.