Javascript Test (mocha) With 'import' Js File
I understand module.export and require mannner: Requiring external js file for mocha testing Although it's pretty usable as long as it's a module, I feel this manner is inconvenien
Solution 1:
I usually include a _test
object containing references to all my "private" internal variables and functions and expose it on exports. In your case:
./app.js
varINFINITY = 'infinity';
functionfoo() {
return'bar';
}
exports._test = {
INFINITY: INFINITY,
foo: foo
}
./test/app-test.js
var app = require('../app.js')
/* ... */it('should equal bar', function() {
expect(app._test.foo()).to.equal('bar');
});
it('should equal infinity', function() {
expect(app._test.INFINITY).to.equal('infinity');
});
Post a Comment for "Javascript Test (mocha) With 'import' Js File"