I know how to use stub to replace one function.
JavaScript
x
3
1
sandbox.stub(Cars, "findOne",
2
() => {return car1 });
3
But now I have a line in my function I want to test that I need to stub that looks like this
JavaScript
1
2
1
Cars.find().fetch()
2
So there is a chain of function here and I’m unsure what I need to do. How do I stub “find” to return something that I can use to stub “fetch”?
Advertisement
Answer
Try this:
JavaScript
1
6
1
sandbox.stub(Cars, "find", () => {
2
return {
3
fetch: sinon.stub().returns(anything);
4
};
5
});
6