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
test: fix assertRejects usage #1890
Conversation
@@ -61,8 +60,7 @@ describe('`enableNetConnect()`', () => { | |||
|
|||
await assertRejects( | |||
got('https://example.test/'), | |||
Error, | |||
'Nock: Disallowed net connect for "example.test:80/"' |
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 a good example of where the test was passing when it had a bug in it - the test expects port 80 when it was actually throwing an error for port 443 (https).
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.
Great catch! I totally misread those docs. Thank you for fixing this.
By the way, would love to consider chai-as-promised here. See #1305 in which we’re migrating from Tap to Chai and Mocha. You can see linked some of the incremental PRs. It’s a big job and we’d love help with it if you’re interested! You can post in that issue to avoid duplicated effort. My pref would be to finish converting to chai before we adopt chai-as-promised. |
@paulmelnikow Is anyone currently working on the tap-to-mocha convertion? Wouldn't want to step on any toes. If not, I could pick up some suites to convert. Specifically talking about assertRejected, I imagine the plan would be something like this then:
|
Best thing is to pick a file that’s still using tap assertions and start converting them. None have been claimed, except there’s one open PR for the Mocha DSL in test_logging. If you post in #1305 when you start, then everyone else will know not to work on that one. And yea, I think the order you’re suggesting makes sense. |
🎉 This PR is included in version 11.9.0-beta.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 11.9.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
As mentioned in #1889, it appears that
assertRejects
is not currently used correctly - the third parameter is the message that the assertion emits if it fails, not a matcher for the exception text.This PR fixes all usages of
assertRejects
to correct expect on the error message. It might also be worth considering migrating to something likechai-as-promised
for a more standard chai based approach.Runkit with an example.