const query = Model.find(conditions, fields, options);
if (someCondition) {
query.populate('someField)
}
query.exec(callback);
Trying to test populate is called
sinon.mock(Model)
.expects('find')
.chain('populate).withArgs('someField')
.chain('exec')
.yields(null, {
foo: 'bar'
});
I get the following error:
Uncaught TypeError: Cannot read property 'emit' of undefined
If I remove the chain for 'populate' it works just fine.
Debugging further it looks like the yields is not returning the mock object causing a failure further in the test.
Trying to test populate is called
I get the following error:
Uncaught TypeError: Cannot read property 'emit' of undefinedIf I remove the chain for 'populate' it works just fine.
Debugging further it looks like the yields is not returning the mock object causing a failure further in the test.