-
-
Notifications
You must be signed in to change notification settings - Fork 698
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
WIP: Update .throw
and add .error
#1021
Conversation
This will definitely improve test readability and give better output to failing tests. I am currently migrating a microservice infra too a new environment and migrating the CD pipeline too and I am having errors such as: Thanks for your effort. |
cd56699
to
72c1b66
Compare
Codecov Report
@@ Coverage Diff @@
## master #1021 +/- ##
==========================================
+ Coverage 93.69% 94.58% +0.89%
==========================================
Files 32 32
Lines 1649 1625 -24
Branches 396 374 -22
==========================================
- Hits 1545 1537 -8
+ Misses 104 88 -16
Continue to review full report at Codecov.
|
I just opened chaijs/check-error#18, and then updated this PR to use that. This is still in a WIP state; it's still missing the This is now definitely a breaking change. In addition to making small adjustments to failed assertion messages (for consistency and simplicity), it also no longer allows This also resolves #1070 (and closes #1071). Also related: chaijs/chai-as-promised#235 |
cd4ef87
to
c294eae
Compare
BREAKING CHANGE: Update failed assertion messages for `.throw` for simplicity, consistency, and correctness. Update `.throw` to only perform criteria matching on `Error` instances.
c294eae
to
aa886d2
Compare
@meeber we're clearing house on the open PRs and issues (as discussed on the team discussion). As this has been a WIP PR open for a while, we're going to close this now - just for housekeeping. @lucasfcosta and I are working on Chai together. We've added https://github.com/chaijs/chai/projects/2 which will cover this so we can track it through to Chai 5. Please don't delete your branch! We'll pick it up and run with it hopefully in the next few days! |
DO NOT MERGE; THIS IS A WORK IN PROGRESS!!
(Note: I'm recreating this PR because I accidentally closed #1015 and don't seem able to re-open it.)
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.