WIP: Update .throw
and add .error
#1015
Closed
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.
DO NOT MERGE; THIS IS A WORK IN PROGRESS!!
I've been doing a lot of work on #930. This turned out to be a lot harder than expected;
.throw
couldn't be updated to simply call.error
internally due to the difference in failed assertion messages between the two. I suspect this is the same kind of issue causing problems in plugins likechai-as-promised
when they try to adapt.throw
.The more I looked at our current
.throw
implementation, the more I realized that the complexity wasn't because of negation as we originally thought but rather because of how the failed assertion messages were being composed. As a result, this PR turned into a pretty big refactor of.throw
to reduce complexity. This also required changing some of.throw
's failed assertion messages to be more consistent.Some notes/thoughts:
.error
to the BDD interface. I'll add the Assert interface later.matchError
anddecribeExpectedError
helper functions should probably be moved to thecheck-error
module..throw
does is assert that a function throws, without taking into account what it throws. This means it will work if the target function throws something besides anError
object (e.g., a string, a number,null
, or evenundefined
). I think it's important that the.throw
logic retain this base functionality. However, when it comes to adding arguments to the.throw
function to perform additional assertions on the value that was thrown, I think we should consider requiring that the object thrown be anError
object. Currently, the behavior of the variouscheck-error
functions is a little sketchy if the object being tested isn't anError
. This problem carries over into thematchError
helper function as well.