New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sinon method chaining weird behaviour #739

phnah opened this Issue Apr 24, 2015 · 2 comments


None yet
2 participants

phnah commented Apr 24, 2015

Sinon.js (v1.14.1) has a weird behaviour in method chaining, not sure it's meant to be or a bug:

This (JSBin):

var myStub = sinon.stub().withArgs(1).returns("one").withArgs(2).returns("two");

Will always return "two" no matter what argument you call myStub with.

On the other hand, this (JSBin):

var myStub = sinon.stub();

works fine. I'm not sure that SinonJS supports chaining or not.

Thanks, guys.


This comment has been minimized.


mantoni commented Apr 24, 2015

The "implementation detail" behind this is, that withArgs and returns returns a "behavior" and not the stub instance. The behaviors can be chained. In your first snippet, you assign a behavior instance to myStub.

I can see that this is not really intuitive, but it's not a bug. Maybe it could be clarified in the docs.

@mantoni mantoni closed this Apr 24, 2015


This comment has been minimized.

phnah commented Apr 24, 2015

Thanks a lot @mantoni.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment