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
Conversation
They now throw if not called with enough arguments when before they would return undefined.
Inspired by a suggestion in #1846. If this merges first, that PR should be assimilated as well. |
Pull Request Test Coverage Report for Build 2559
💛 - Coveralls |
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" |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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 😆
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: |
@huttli Great catch! Thanks. I pushed the fix. |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice 👍
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. |
This has been published to NPM as |
They now throw if not called with enough arguments when before they would return undefined.
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 returnundefined
. Now it throws.callsArg
would previously throw aTypeError
complaining that the param (undefined
) was not afunction
.They all throw the same
TypeError
now with a consistent message.