vendredi 5 février 2016

Using external class during client side Mocha unit testing

I am running unit tests on a javascript class using Mocha using the follow methodology, firstly the test:

var base = require('../moduleone.js');

describe("some test", function() {
    it("description", function() {
    var check = base.toBeTested(dummyValue)
    //test is here ...
    });
});

the moduleone.js containing function to be tested:

function toBeTested(category){
    //below I calling an assert function defined in moduletwo
    //works fine when running in browser
    assert(type(category)=='string','category is string type');
    //more code..
    return something

module.exports.toBeTested = toBeTested;

moduletwo.js:

function assert(outcome, description) {
    //see code.tutsplus.com quick and easy javascript testing with assert
    var li = outcome ? 'pass' : 'fail';
    if (li == 'fail') {
        console.log('FAIL: '+description);
    }
    else {
        console.log('PASS: '+description);
    }
}

The issue I have is mocha doesn't know anything about moduletwo and when the moduleone function calles the function in moduletwo mocha throws a ReferenceError: assert is not defined. How can I link all my dependencies so that mocha can see them?

Aucun commentaire:

Enregistrer un commentaire