-
-
Notifications
You must be signed in to change notification settings - Fork 772
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 throwsArg(index) to stubs #1319
Conversation
This was requested through sinonjs#1270
This PR looks good to me. However, I cannot figure out why coveralls thinks that this should not be merged. So, I tried to run the coverage report locally, but it doesn't generate a nice HTML representation. @mantoni do you know the magic incantation to get the mochify-istanbul to play nice and generate an HTML coverage report? |
@mroderick You can run |
Coverage dropped by >= 1%. Coveralls is configured to block the commit when that happens. I'm not 100% sure why that is the case, but I believe it has to do with the way it's tracking coverage. I submitted a PR to attempt to fix this. |
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.
Thanks for the contribution. There are just a few missing tests.
@@ -113,6 +113,7 @@ var proto = { | |||
this.exception || | |||
typeof this.returnArgAt === "number" || | |||
this.returnThis || | |||
typeof this.throwArgAt === "number" || |
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.
Please add a test.
@@ -92,6 +92,7 @@ var proto = { | |||
|
|||
delete this.returnValue; | |||
delete this.returnArgAt; | |||
delete this.throwArgAt; |
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.
Please add a test.
@seppevs Any plans to finish this PR? It looks like a solid addition. |
@fearphage sorry I'm quiet busy. I tried a few weeks ago to add the tests, but I couldn't find where I should add them. |
@seppevs Completely understandable. Would you mind opening/unlocking the PR so others can push to your branch to complete this PR? I'm not sure how to describe it, because I've never done it before. There is (or at least was) a checkbox somewhere in the right column that said something along the lines of "allow other collaborators to push to your PR" or something along those lines. If you check that box, someone else can help you wrap this up. Also thank you very much for your contribution. |
@fearphage "Allow edits from maintainers." is checked. The description when I hover over it:
|
I'm going to let someone else review and merge. @sinonjs/sinon-core |
docs/_releases/v1.17.6/stubs.md
Outdated
|
||
Causes the stub to throw the argument exception at the provided index. | ||
|
||
`stub.returnsArg(0);` causes the stub to throw the first argument exception. |
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.
Copy pasted from returnsArg
?
lib/sinon/behavior.js
Outdated
@@ -126,6 +127,8 @@ var proto = { | |||
return args[this.returnArgAt]; | |||
} else if (this.returnThis) { | |||
return context; | |||
} else if (typeof this.throwArgAt === "number") { | |||
throw args[this.throwArgAt]; |
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.
I think this should test whether the function was called with enough arguments to throw the argument at the given index.
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.
That makes sense. What's the expected behavior if there aren't enough params?
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.
I think it should throw an exception. I know, it sounds ironic in this context, but an exception with a more telling message and not throwing undefined
makes sense, I think. We do something similar in yield
.
For completeness, this feature should also be mirrored in the |
@mantoni Is that the last bit? I'd prefer to do all the changes at once instead of a few at a time. |
Yes, sorry. It came to my mind too late. I didn't do this intentionally. We can also merge this as is and add the spy API separately. |
@fearphage Thank you! |
Since this is an expansion of the API, I think we should publish a new |
@mroderick Yes, true. Are you doing it? |
I concur. Minor seems fitting. |
Fixes issue #1270 by adding a
throwsArg(index)
method to stubsI have added unit tests & docs.