Skip to content
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

How do we verify stub called with argument that is an array #953

Closed
sudhirbits opened this issue Dec 17, 2015 · 4 comments
Closed

How do we verify stub called with argument that is an array #953

sudhirbits opened this issue Dec 17, 2015 · 4 comments

Comments

@sudhirbits
Copy link

argument = ["1","2","3"] to a sinon stub.
I wish to check the argument and return value. I am unable to do the same using

stub.withArgs(argument).return(value); // its unable to match
stub.withArgs(sinon.match.array).return(value); // able to match
stub.withArgs(sinon.match.array.and(sinon.match.has("length", 3) // able to match

I am able to debug using WebStorm and verify that argument is passed to the stub.

Please help.

@mroderick
Copy link
Member

We are trying to keep the GitHub issues list tidy and focused on bugs and feature discussions. This ticket looks like a usage question, please post it to the Sinon.JS mailinglist, so the bigger community can help answer your questions.

If you feel that your topic is an issue with Sinon.JS, please open a new ticket and follow the guidelines for reporting an issue.

@sudhirbits
Copy link
Author

thanks. I will contact the forum, thanks for your time. sinon is cool btw :)

@gunar
Copy link

gunar commented Dec 7, 2016

For anyone looking, here is the answer by @mroderick himself.

var expectedValue = [1, 2, 3];
var myStub = sinon.stub;

// let's pretend this is the call you want to verify
myStub(expectedValue);

var firstArgument = myStub.getCall(0).args[0];
assert.equal(firstArgument, expectedValue);

@sdeering
Copy link

Or stubName.getCall(0).thisValue.$$paramName;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants