Skip to content
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

Fix typings of toThrowWithMessage, support unconstructable errors #475

Merged
merged 4 commits into from Jul 18, 2022
Merged

Fix typings of toThrowWithMessage, support unconstructable errors #475

merged 4 commits into from Jul 18, 2022

Conversation

GerkinDev
Copy link
Contributor

What

This PR fixes typings issues noted in #472, and adds support to unconstructable errors (such as abstract classes or not taking a message string as first arg) to be passed as error class.

Why

See #472. Moreover, toThrowWithMessage was unusable with AssertionError from the node assert module.

Notes

The matcher first tries to instantiate the type with the message (toStringed in case it was a regex).
If the instantiation fails, it creates a new Error on which it sets the name & message in order to be correctly printed as expected in the message.

Housekeeping

  • Unit tests
  • Documentation is up to date
  • No additional lint warnings
  • Typescript definitions are added/updated where relevant

@codecov
Copy link

codecov bot commented Jul 18, 2022

Codecov Report

Merging #475 (7fa174d) into main (14830d5) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main      #475   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           71        71           
  Lines          575       582    +7     
  Branches       148       148           
=========================================
+ Hits           575       582    +7     
Impacted Files Coverage Δ
src/matchers/toThrowWithMessage.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 14830d5...7fa174d. Read the comment docs.

@GerkinDev GerkinDev changed the title Fix/to throw with message Fix typings of toThrowWithMessage, support unconstructable errors Jul 18, 2022
@SimenB SimenB linked an issue Jul 18, 2022 that may be closed by this pull request
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweet, thanks!

@GerkinDev
Copy link
Contributor Author

Hi @SimenB , do you know when this will be released ? I'm heavily relying on node assert and I can't test thrown errors correctly without this.

Thanks !

@SimenB
Copy link
Member

SimenB commented Aug 4, 2022

@GerkinDev
Copy link
Contributor Author

Thanks so much !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Type definition of .toThrowWithMessage() is broken
2 participants