According to this https://developer.enonic.com/docs/writing-unit-tests, when adding mock functions, Can we pass params to mock function?
In Java Mockito mock functions, don’t execute any statements. Instead, it’s just a “stub” or a placeholder for the real method. But it seems enonic mock function executes inside statements. Is it execute inside mock functions instead of return values?
exports.getValue = function() {
let value = Math.random();
console.log("value: "+ value);
return value;
}
const valueCreator = require('/lib/valueCreator.js');
exports.get = function() {
const value = valueCreator.getValue();
if (value < .5) {
return "Low";
} else {
return "High";
}
}
t.mock('/lib/valueCreator.js', {
getValue: function () {
return '1';
}
});
exports.testValue = function () {
var service = require('./myModule');
var result = service.get();
t.assertEquals('High', result);
};