Sinon: Consecutive calls with expectation about args

Created on 19 Nov 2016  路  5Comments  路  Source: sinonjs/sinon

I want to create a mock with the following expectations:

  • it is called twice
  • on first call it is called with args \
  • on second call it is called with args \

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.

Duplicate stale

Most helpful comment

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 :(

All 5 comments

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

Related: https://github.com/sinonjs/sinon/issues/992
Call for documentation: https://github.com/sinonjs/sinon/issues/1432

We would welcome PRs to improve this :)

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

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 :(

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.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NathanHazout picture NathanHazout  路  3Comments

tinganho picture tinganho  路  3Comments

akdor1154 picture akdor1154  路  4Comments

JakobJingleheimer picture JakobJingleheimer  路  3Comments

sudhirbits picture sudhirbits  路  4Comments