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

Add Sinon.assert.calledOnceWithExactly #2006

Closed
dpmott opened this issue Apr 4, 2019 · 5 comments
Closed

Add Sinon.assert.calledOnceWithExactly #2006

dpmott opened this issue Apr 4, 2019 · 5 comments

Comments

@dpmott
Copy link
Contributor

dpmott commented Apr 4, 2019

Is your feature request related to a problem? Please describe.
Closely related to #1247, but in this case I'd like to be able to type Sinon.assert.calledOnceWithExactly(stub, arg1, ... argN)

Describe the solution you'd like
I believe that there just needs to be an entry in assert.js to facilitate this. I'm not entirely sure what the failure message (including interpolated variables) should be though.

Possibly just this addition to assert.js?
mirrorPropAsAssertion("calledOnceWithExactly", "expected %n to be called once with exact arguments %D");

Describe alternatives you've considered
The equivalent functionality with today's Sinon is:

Sinon.assert.calledOnce(stub);
Sinon.assert.calledWithExactly(stub, arg1, ...argN);

If I could get some agreement on what the assertion message should be, then I'd be happy to generate a PR.

@brandonau24
Copy link
Contributor

@dpmott This is possible with a spy assuming you're on the latest version. The beginning of the page says, spies can record arguments which is what you seem to be looking for. Stubs are only for pre-programming behavior like forcing a function to return a specific value. Hope this helps!

fatso83 added a commit that referenced this issue May 27, 2019
ref discussions in #1971, #1686, #2006

Makes it clearer how these methods work. It was unclear to me whether these methods would return true if one of many calls had been made using these args (although that would have made it a duplicate of the `calledWith*` methods).
fatso83 added a commit that referenced this issue May 27, 2019
* Clarify exactly how calledOnceWith* works

ref discussions in #1971, #1686, #2006

Makes it clearer how these methods work. It was unclear to me whether these methods would return true if one of many calls had been made using these args (although that would have made it a duplicate of the `calledWith*` methods).
@fatso83
Copy link
Contributor

fatso83 commented May 27, 2019

@brandonau24 I believe you are talking about something else. @dpmott is addressing the feature disparity between the assertions available on the spies and the standalone assertions that can be invoked on spies. Furthermore, everything a spy can do, a stub can do as well: a stub simply extends the spy api. So all the spy assertions are already available on a stub, so you can always use a stub in place of a spy - it's more of a semantical discussion whether or not to explicitly use a spy.

@dpmott I'd try to make the assertion message even clearer (ref 88a7150 and the whole discussion in #1971 (comment)).

+ What about "expected %n to be called once and with the exact arguments %D"?
- What about "expected %n to be called once with exact arguments %D"?

So, yes, please provide a PR :-)

@stale
Copy link

stale bot commented Jul 26, 2019

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 Jul 26, 2019
@dpmott
Copy link
Contributor Author

dpmott commented Jul 26, 2019

Thanks for the input. Will do.

@fatso83
Copy link
Contributor

fatso83 commented Sep 23, 2019

Closed by #2080 !

@fatso83 fatso83 closed this as completed Sep 23, 2019
franck-romano pushed a commit to franck-romano/sinon that referenced this issue Oct 1, 2019
* Clarify exactly how calledOnceWith* works

ref discussions in sinonjs#1971, sinonjs#1686, sinonjs#2006

Makes it clearer how these methods work. It was unclear to me whether these methods would return true if one of many calls had been made using these args (although that would have made it a duplicate of the `calledWith*` methods).
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

3 participants