How do I stub a chain of methods in Sinon?


#1

So I’m new to unit testing in Meteor 1.3 and I’m using Sinon as specified in the Meteor Guide.

I know how to use stub to replace one function.

sandbox.stub(Cars, "findOne",
			() => {return car1 });

But now I have a line in my function I want to test that I need to stub that looks like this

Cars.find(selector).fetch()

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”?


#2

Possibly of interest: http://guide.meteor.com/testing.html#mocking-the-database