javascript - How to properly require modules from mocha.opts file -


i'm using expect.js library mocha unit tests. currently, i'm requiring library on first line of each file, this:

var expect = require('expect.js');  describe('something', function () {     it('should pass', function () {         expect(true).to.be(true); // works     }); }); 

if possible, i'd remove boilerplate require code first line of each file, , have unit tests magically know expect. thought might able using mocha.opts file:

--require ./node_modules/expect.js/index.js 

but following error when running test:

referenceerror: expect not defined

this seems make sense - how can know reference expect in tests refers exported expect.js library?

the expect library getting loaded, if change path non-existent mocha says:

"error: cannot find module './does-not-exist.js'"

is there way accomplish want? i'm running tests gulp task if perhaps help.

you requiring module figured out, symbols module export won't automatically find global space. can remedy own helper module.

create test/helper.js:

var expect = require("expect.js")  global.expect = expect; 

and set test/mocha.opts to:

--require test/helper 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -