I am trying to unit test:
myModel.find({"id": someId}, callback)
.sort({timestamp: -1})
.limit(100)
I used sinon-mongoose and came up with the following
myModel
.expects('find').withArgs({"id": 'def'})
.chain('exec')
.yields(null, 'abc')
.chain('sort').withArgs({timestamp: -1})
.chain('limit').withArgs(100);
However, I run into the issue that the done function is not being called and the test times out. Anyone have experience stubbing the regular callback over the exec callback using sinon-mongoose?
If I change my model code to:
myModel.find({"id": someId}
.exec(callback)
.sort({timestamp: -1})
.limit(100)
The unit test works. Thus, I think it's a problem in stubbing the exec callback vs regular callback.