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.
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
Add assert.rejects and assert.not.rejects methods for promises #132
base: master
Are you sure you want to change the base?
Add assert.rejects and assert.not.rejects methods for promises #132
Changes from 1 commit
bdd8b6f
f007c7e
7a03d8c
bbd9ba6
74b0d02
009b09c
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
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.
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.
I added this in because I was confused when I changed the test to
$.throws(() => { throw new Error('world') }, /world/);
and it still passed. Wouldn’t the same thing happen if there was a regression in throws itself that would go unnoticed without this check?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.
(I think this is – and the one above; same issue – are the only two I’m confused on. Accepted all other changes and happy to go with what you think is best for on these.)
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.
The assertion helper is saying: given X function, an error (a) should be thrown and (b) the thrown error should match {this condition}. The condition can be defined via a function, a RegExp, or a string.
So this test has X function, which happens to
throw new Error('hello')
, and the assertion is saying X must throw an Error that matches the/world/
pattern.In the original test, this fails (obv because
"hello"
does not match/world
) and so the assertions within thecatch
block run, and correctly find that the "Expected function to throw exception matching/world/
pattern" message appears, among others.When you change the X to be:
This doesnt fail the assertion, because
"world"
does match the/world
pattern. The assertion passed. So in this case, the checks within thecatch
block never run.Testing negated fail conditions can be a trip, haha
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.
I kinda feel like it could be helpful to make that work via
which maybe that doesn't make sense.. but it'd be nice to be able to chain
throws()
withmatch()
rather than having a regex overerr.message
🤔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.
Thanks but the current API is much preferred and has prior art from many existing test runners and/or assertion libraries. It would also add a bunch of additional changes for the same (but more verbose) result.