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

assert.calledOnceWithMatch #84

Closed
magnars opened this issue Feb 10, 2012 · 7 comments
Closed

assert.calledOnceWithMatch #84

magnars opened this issue Feb 10, 2012 · 7 comments

Comments

@magnars
Copy link

magnars commented Feb 10, 2012

assert.match is the best thing way before sliced bread, and I want it with everything. But most of all I want it with assert.calledOnceWith.

The usecase that prompted this issue was todays snafu:

fs.createReadStream(__dirname + '/blank-config-file.js');

stubbing out this so-and-so makes for some unwieldy getCall and args incantations. Sinon is for beauty, and let me tell you - this code I just wrote isn't gonna win any pageants. :)

@mantoni
Copy link
Member

mantoni commented May 12, 2012

Should it assert that it was called only once and the given arguments match? Or should it assert that it was called once with the arguments but it might have been called again with different arguments?

@cjohansen
Copy link
Contributor

Scratch the original comment.... assert.calledWithMatch is in :)

@meetmangukiya
Copy link

Wouldn't calledOnceWithMatch imply one more assertion that it was called only once? In which case calledWithMatch is not the same as calledOnceWithMatch.

@mantoni
Copy link
Member

mantoni commented Sep 29, 2020

Called once with match is on the way: #2294

@meetmangukiya
Copy link

awesome!

@fatso83
Copy link
Contributor

fatso83 commented Sep 30, 2020

@meetmangukiya The assertions that check two things are ambiguous in name. That's why I do not use them. We had this discussion multiple times: calledOnceWithMatch could mean

  • the spy was called one or several times, and of those calls, it was at least one call that matched.
  • the spy was called one or several times, and of those calls, exactly one single call matched.
  • the spy was called exactly one time and that single call matched.

Of course, if you check the docs, you know :)

We do have the calledExactly* methods as well. If you want to be precise for the casual reader, I'd just do two assertions.

@mantoni
Copy link
Member

mantoni commented Sep 30, 2020

Since we do have these combined assertions now, I tend to always read them as "and" expressions of the underlying assertions. They're basically short hands to fold two assert calls into one. That's a rule we should stick with for consistency, I think.

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

5 participants