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

Made callsArg, returnsArg, and throwsArg more strict #1848

Merged
merged 4 commits into from Jul 6, 2018

Conversation

fearphage
Copy link
Member

All will now throw if not called with enough arguments when before they would return undefined.

Example:

stub.returnsArg(5)('not', 'enough', 'params') would previously return undefined. Now it throws.

callsArg would previously throw a TypeError complaining that the param (undefined) was not a function.

They all throw the same TypeError now with a consistent message.

They now throw if not called with enough arguments
when before they would return undefined.
@fearphage
Copy link
Member Author

Inspired by a suggestion in #1846. If this merges first, that PR should be assimilated as well.

@coveralls
Copy link

coveralls commented Jun 25, 2018

Pull Request Test Coverage Report for Build 2559

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 22 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.1%) to 84.853%

Files with Coverage Reduction New Missed Lines %
sinon/behavior.js 22 62.75%
Totals Coverage Status
Change from base Build 2557: 0.1%
Covered Lines: 1787
Relevant Lines: 2035

💛 - Coveralls

@fearphage
Copy link
Member Author

fearphage commented Jun 25, 2018

Note: This could be considered a breaking change to people who were expecting the silent fall through (failure?). I'm not sure. I'll leave that up to the semver gods. 😉

function (error) {
return error instanceof TypeError
&& error.message ===
"throwArgs failed: 3 arguments required but only 2 present"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of note: This message changed: throwArgs (typo?) became throwsArg.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, seems like a typo. There is throwArg implemented on calls, but singular. throwArgs doesn't even make sense 😆

@huttli
Copy link
Contributor

huttli commented Jun 26, 2018

There is an error at the number vs. arg index in the old error messages for throwsArg. According to the doc, the index starts at 0. I think the check should be done between these two numbers: args.length and throwArgAt +1.
Please use the correct number in the error message thrown.

@fearphage
Copy link
Member Author

@huttli Great catch! Thanks. I pushed the fix.

@fearphage fearphage closed this Jun 27, 2018
@fearphage fearphage reopened this Jun 27, 2018
@mroderick
Copy link
Member

Inspired by a suggestion in #1846. If this merges first, that PR should be assimilated as well.

Does that mean that we should not merge this, until #1846 is ready to merge?

@fearphage
Copy link
Member Author

It doesn't matter which one goes first honestly. It would be easier and more convenient (for the contributor) to merge that PR first and then I can update this one to include it.

Copy link
Member

@mantoni mantoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice 👍

@mantoni
Copy link
Member

mantoni commented Jul 3, 2018

Regarding versioning, I'd classify this as a bug. If it's breaking someones test, it's highlighting an issue that was always there and also needs fixing. Neither the semantics nor the API has changed.

@mroderick mroderick added the semver:patch changes will cause a new patch version label Jul 6, 2018
@mroderick mroderick merged commit c3a978a into sinonjs:master Jul 6, 2018
@mroderick
Copy link
Member

This has been published to NPM as sinon@6.1.2

@fearphage fearphage deleted the stricter-is-better branch July 6, 2018 20:01
franck-romano pushed a commit to franck-romano/sinon that referenced this pull request Oct 1, 2019
They now throw if not called with enough arguments
when before they would return undefined.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver:patch changes will cause a new patch version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants