test: fix assertRejects usage#1890
Conversation
| await assertRejects( | ||
| got('https://example.test/'), | ||
| Error, | ||
| 'Nock: Disallowed net connect for "example.test:80/"' |
There was a problem hiding this comment.
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).
paulmelnikow
left a comment
There was a problem hiding this comment.
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 nock#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.
As mentioned in #1889, it appears that
assertRejectsis 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
assertRejectsto correct expect on the error message. It might also be worth considering migrating to something likechai-as-promisedfor a more standard chai based approach.Runkit with an example.