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 I verify arguments passed to the stub ? #26

Open
walshe opened this issue May 17, 2017 · 2 comments
Open

how do I verify arguments passed to the stub ? #26

walshe opened this issue May 17, 2017 · 2 comments

Comments

@walshe
Copy link

walshe commented May 17, 2017

In code below I would like to check the params that I passed to the stubbed function..

const sinon = require('sinon');
var sinonStubPromise = require('sinon-stub-promise');
sinonStubPromise(sinon);

var serviceRequest = require("../../mysql/models")['ServiceRequest'];
var providerRequest = require("../../mysql/models")['ProviderRequest'];

var serviceRequestCreateStub = sinon.stub(serviceRequest, 'create');
var providerRequestCreateStub = sinon.stub(providerRequest, 'create');

...
...

serviceRequestCreateStub.callsFake(function(obj){ /* would like to verify that obj passed in was correct here*/}).returnsPromise().resolves({},true);

@a-b-r-o-w-n
Copy link
Contributor

I'm not exactly sure what you are trying to do. The documentation for callsFake seems like it just allows you to override the behavior of the stub when invoked.

In order to verify that your stub was called with the correct args, you could do myStub.withArgs(obj).returnsPromise().resolves({}, true).

Hope that helps!

@walshe
Copy link
Author

walshe commented Jul 4, 2017

thanks, I got it to work @astephenb
btw I notice that when the args are not called properly that the error message is pretty bad and not very easy to diagnose

providerRequestCreateStub.withArgs({
vroomMessageUuid: messages[0].data.attributes.messageUuid,
recipient: messages[0].data.attributes.to,
timestamp: sinon.match.any,
twilioMessageSid: "12345678"
}).returnsPromise().resolves({},true);

is there anyway to tell it to give a more meaningful error message ? thanks

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

2 participants