How to properly require modules from mocha.opts file

后端 未结 3 1573
天命终不由人
天命终不由人 2021-02-03 10:52

I\'m using the expect.js library with my mocha unit tests. Currently, I\'m requiring the library on the first line of each file, like this:

var expect = require         


        
3条回答
  •  一生所求
    2021-02-03 11:41

    You are requiring the module properly but as you figured out, the symbols that the module export won't automatically find themselves into the global space. You can remedy this with your own helper module.

    Create test/helper.js:

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

    and set your test/mocha.opts to:

    --require test/helper
    

提交回复
热议问题