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

Consecutive calls with expectation about args #1193

Closed
mir3z opened this issue Nov 19, 2016 · 5 comments
Closed

Consecutive calls with expectation about args #1193

mir3z opened this issue Nov 19, 2016 · 5 comments

Comments

@mir3z
Copy link

mir3z commented Nov 19, 2016

I want to create a mock with the following expectations:

  • it is called twice
  • on first call it is called with args <X> and returns <R1>
  • on second call it is called with args <Y> and returns <R2>

When I'm trying to do:

const mock = mock().twice();
mock.onCall(0).withArgs(0);
mock.onCall(1).withArgs(1);

I see error Defining a stub by invoking "stub.onCall(...).withArgs(...)" is not supported. Use "stub.withArgs(...).onCall(...)" to define sequential behavior for calls with certain arguments.

but if I follow the advice I'm unable to set different args and response for consecutive calls.

@mroderick
Copy link
Member

The withArgs implementation in sinon.mock overwrites the stored value on each call. This is unfortunate, and should be improved.

Related: #992
Call for documentation: #1432

We would welcome PRs to improve this :)

@mroderick
Copy link
Member

I am closing this as duplicate, since #992 reported it earlier.

@tkissing-work
Copy link

So you closed this as a dupe of #992 but then you closed that because now the behavior is documented?
That does not actually solve the problem :(

@stale
Copy link

stale bot commented Jan 13, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 13, 2018
@stale stale bot closed this as completed Jan 20, 2018
@priyanka-deshmukh
Copy link

@mir3z Have you found solution for this? I am also trying to do the same thing over here

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

No branches or pull requests

4 participants