For example: my math_util.js is
var MathUtil = function(){
function add(a,b){
return a + b;
}
return {
add: add
};
}
I'll use Jest to test add(). So I'll write
test('add', ()=>{
expect(MathUtil().add(1,1)).toBe(2);
});
But I get MathUtil
is undefined or MathUtil()
is not a function.
I also tried to use require()
or import
. But MathUtil
doesn't have module.export
or export
.
So how to write unit test for javascript revealing module pattern with Jest?
Note: I've a project with all scripts written in revealing module pattern so convert all to ES2015 module may not be practical.