I want to create a mock with the following expectations:
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.
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
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 :(