-
Notifications
You must be signed in to change notification settings - Fork 781
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
Assert: Add assert.rejects
.
#1238
Conversation
fe1567c
to
7568663
Compare
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.
This looks like a great start! Are there any tests that show assert.rejects
causing a test failure if the promise is fulfilled? I only gave this a cursory view as my plane landed, so apologies if I missed something.
7568663
to
ac61264
Compare
@platinumazure - Thanks for reviewing! You are absolutely right, I was actually somewhat confused about how that worked as I'm used to failing assertions failing CI (which is to be avoided), but a testing framework has to creatively work around that to ensure that its failures are correct too. I did a bit of digging after your comment to see how this was handled for things like tldr; I just pushed an update with tests around when |
I've taken another quick look and it looks promising. I'll give it a full review this week. Naturally, I'll also want @trentmwillis to take a look as well. Thanks for your hard work! |
Hehe. Thank you, got a good chuckle out of this pun this morning. 😝 |
I assume we don't want to support As-is, the documentation tells me the following:
However, current code supports I understand string is a problem because of ambiguity with the optional message parameter. I also understand that we (I think?) discourage throwing things that aren't objects. But in that case we shouldn't showcase it in the documentation. The first usage example is currently Two minor suggestions, if we indeed want to discourage throwing non-objects:
|
docs/assert/rejects.md
Outdated
}; | ||
|
||
assert.rejects( | ||
Promise.reject("error"), |
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.
(*)
ac61264
to
af87708
Compare
Thanks for the review @Krinkle! I just pushed some changes which (assuming I understood your concerns properly) should address your bullet points. Specifically:
Let me know what you think! |
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.
Overall, looks good to me. Just some minor things.
@Krinkle, when you have a moment, can you review again to verify your concerns were addressed? (Looks to me like they were.)
| name | description | | ||
|--------------------|--------------------------------------| | ||
| `promise` (thenable) | promise to test for rejection | | ||
| `expectedMatcher` | Rejection value matcher | |
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.
This name is inconsistent with the function signature given. I'd prefer we use expectedMatcher
throughout as it makes more sense semantically.
docs/assert/rejects.md
Outdated
specific set of circumstances, use `assert.rejects()` for testing and | ||
comparison. | ||
|
||
The `expected` argument can be: |
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.
expected
-> expectedMatcher
docs/assert/rejects.md
Outdated
```js | ||
QUnit.test( "rejects", function( assert ) { | ||
|
||
assert.rejects(new Error("some error description")); |
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.
This is an invalid example, right?
docs/assert/rejects.md
Outdated
"`rejectionValue.toString()` contains `description`" | ||
); | ||
|
||
// Using a custom error like object |
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.
Nit: inconsistent indentation.
src/assert.js
Outdated
message = expected; | ||
expected = undefined; | ||
} else { | ||
message = "rejects does not accept a string value for the expected argument.\n" + |
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.
Can we put assert.rejects() does not accept a string value...
? I think it is just a bit clearer/more helpful.
@rwjblue, no pressure, but do you think you'll update this soon? I'd like to see it in the next release if possible but it can always be in the one after as well 🙂 |
af87708
to
dc451e6
Compare
@trentmwillis - Thanks for the review! I cleaned up the docs and fixed the error message, I believe that addresses all of the outstanding review comments. |
Thanks a bunch! |
Closes #1204