I am using sinon with nodejs .
How do I ensure that my log4j
is being called once in my unit testing.
I am getting this error:
TypeError: Attempted to wrap undefined property info as function.
main.js:
let log = require('log4js').getLogger("main");
...
personDao.updatePerson(param,
(updatePerson) => updatePersonCallBack(updatePersonResult));
...
let updatePersonCallBack= exports.updatePersonCallBack= (result) => {
log.info("SUCCESS", result)
}
main.spec.js:
it('updatePersonCallBack', (done) => {
let getInfoSpy = sinon.spy(log, "info");
let updatePersonResult= 1;
main.updatePersonCallBack(updatePersonResult);
should.equal(getInfoSpy.callCount, 1);
done();
});
you need to import/require log in spec/test file as well so that spy will identify log and info as its method. As log is not declared in the spec/test file, it will throw undefined error.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.