Repository navigation
Add support for passing a function to stub.throws(...) - #1511
Merged
Merged
Conversation
noisecapella
force-pushed
the
more-descriptive-error-stack
branch
from
August 3, 2017 16:19
56ca44f to
723c706
Compare
Contributor
|
Looks good, but need to test it to get a feel for it :-) |
Member
|
Nice work! I'm missing test cases verifying that the error object is now created lazily for all three cases. |
Contributor
Author
|
I added some tests, are those assertions what you were thinking of? |
noisecapella
force-pushed
the
more-descriptive-error-stack
branch
from
August 4, 2017 14:49
9e423d9 to
bde1204
Compare
Member
|
In general, yes. However, you're now testing the implementation details, not the behavior. I was thinking of asserting the point in time a given function is actually called, or stubbing the |
Contributor
Author
|
I see, I'll make the change |
noisecapella
force-pushed
the
more-descriptive-error-stack
branch
from
August 4, 2017 15:33
bde1204 to
55c3f5f
Compare
fatso83
approved these changes
Aug 4, 2017
fatso83
left a comment
Contributor
There was a problem hiding this comment.
Think those tests look much better.
Member
|
Great tests! Thank you very much 👍 |
2 tasks
Contributor
|
This introduced regression #1526. Mind taking a look at it, @noisecapella? |
Contributor
Author
|
Yes I'll take a look |
2 tasks done
franck-romano
pushed a commit
to franck-romano/sinon
that referenced
this pull request
Oct 1, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose (TL;DR) - mandatory
Fixes #1507
This PR adds functionality to allow
stub.throws(...)to accept a function as an argument. This function is invoked at the point that the exception is thrown which allows the end user to have a more descriptive stack trace for the error. This also delays instantiating theErroruntil it is thrown (except when the user has already instantiated it) to create a more detailed stack trace.Background (Problem in detail) - optional
At least in node, the stack trace for an
Erroris created when the object is instantiated rather than when it's thrown (from here). The stack trace is sometimes useful in figuring out what pieces of code are involved with an error. Currently errors used inthrows(...)are instantiated by the caller or soon after in the setup of the stub which results in a stack trace showing where the setup occurred rather than where the problem occurred.Solution - optional
In cases where the exception is not passed into
throws(...), a function which will instantiate the exception is used internally instead and assigned to a new fieldexceptionCreator. When the exception is thrownexceptionCreatoris instantiated and the result is assigned toexceptionto allow inspection viatoStringor other means.How to verify - mandatory
To see the difference in stack trace see the test I included in the linked issue.