I have two JavaScript files and would like to export the file with module pattern to another file. The file with module pattern, I would like to export only public members. When I try to execute the test, it says that "Calculator is not a constructor".
file: calculator.js
var Calculator = function(){
var total = null;
return {
add: function(x,y){
total = x + y;
},
getTotal: function(){
return total;
};
display: function(){
console.log(total);
}
}
}
second file: testCalculator.js
const calculatorObj = require('calculator.js');
describe("Calculator test suite", function(){
var calculatorObj = new Calculator();
it('Verify sum method', function() {
try{
calculatorObj.add(5,5);
//assertive
expect(10, calculatorObj.getTotal());
}
catch(err)
{
alert(err);
}
});
});
module.exports = function(){