Sinon: How do we verify stub called with argument that is an array

Created on 17 Dec 2015  ·  4Comments  ·  Source: sinonjs/sinon

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.

Most helpful comment

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);

All 4 comments

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.

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

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);

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

optimatex picture optimatex  ·  4Comments

zimtsui picture zimtsui  ·  3Comments

kevinburkeshyp picture kevinburkeshyp  ·  4Comments

stephanwlee picture stephanwlee  ·  3Comments

akdor1154 picture akdor1154  ·  4Comments