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

1,768 views
Skip to first unread message

Sudhir Ravindramohan

unread,
Dec 18, 2015, 4:10:23 AM12/18/15
to Sinon.JS

argument = ["1","2","3"] to being passed to a sinon stub. 

I wish to check the argument and return value. I am unable to do the same using


  1. stub.withArgs(argument).return(value); // its unable to match
  2. stub.withArgs(sinon.match.array).return(value); // able to match
  3. 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.

Morgan Roderick

unread,
Dec 22, 2015, 11:04:37 AM12/22/15
to sin...@googlegroups.com
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);

--
You received this message because you are subscribed to the Google Groups "Sinon.JS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sinonjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sudhir Ravindramohan

unread,
Dec 22, 2015, 12:38:06 PM12/22/15
to Sinon.JS
Thanks. 
Reply all
Reply to author
Forward
0 new messages