I am new to node.js, and in most of the codes I have seen, I do not see inline constructor IoC / DI constructors.
Instead, the node.js require () extension is usually required to create local vars that allow the export of external modules.
But when writing unit tests (which isolate a single layer / function), how do you mock the modules available through the vars you created?
/helpers/dataHelper.js
var dataModel = require('../models/dataModel.js');
var getFormattedDataForRegion = function(region, callback) {
var data = {};
}
/tests/dataHelperTests.js
describe('dataHelper', function(){
it('getFormattedDataForRegion returns expected response', function(done){
var expectedData = {};
dataHelper.getFormattedDataForRegion("west", function(data){
expect(data).to.eql(expectedData);
done();
});
});
source
share