I am using Mocha for testing a Node.js command line app:
describe('#call', function () {
var nconf = require('nconf'); //is this the best place for this?
before(function () {
//var nconf = require('nconf'); i'd rather define it here
nconf.use('memory');
nconf.set('fp','data_for_testing/csvfile.csv');
nconf.set('mptp','map_ivr_itg');
nconf.set('NODE_ENV','dev_local');
});
it('should run without throwing an error or timing out', function (done) {
var start = require('../lib/setup');
start.forTesting(done);
start.run(nconf); //need nconf to be defined here
});
});
I want to use the Mocha framework right, but the only way I can get the nconf var defined in the it() function is to define it outside the before() function. Is the best way to do it?
var nconf = null; before(function () { nconf = require('nconf'); nconf.use('memory'); });beforecall but you do not specify any reason why. If there is no compelling reason for you to callrequireinside thebeforethen it is wholly a matter of opinion where the call should go. I organize my Mocha files so that they test one library per file. With this organization, there is no discernible benefit to have therequirecall anywhere else than at the top, with all the other calls.