I am new to UnitTest. I have a setData function and trying to write test to it with mocha chai. I trying to mock the function2.setCode function that require from other module and assert it has been call when test the setData function. But have error about wrap undefined property when test. Anyone can help how to achieve that?
const function2 = require(../function2)
function setData(req) {
if (!req) {
return;
}
const data = function1(req);
if (data) {
const function2 = new function2(req);
if (function2) {
function2.setCode(data);
);
}
}
}
My draft
describe('test', ()=>{
context('setData', ()=>{
it('function2.setCode should be call', ()=>{
let mock = mock(setData);
mock.expects("setCode").once();
setData();
mock.verify();
})
})
}