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

Allow DeveloperError Jasmine matchers to accept regex for messages #12338

Merged
merged 4 commits into from
Dec 9, 2024

Conversation

jjspace
Copy link
Contributor

@jjspace jjspace commented Nov 25, 2024

Description

  • The builtin .toThrowError() and .toBeRejectedWithError() matchers accept a string or regex for the expected result. If a regex is provided it will test against that instead of an exact match. This is useful to allow a little flexibility, especially for errors with dynamic parts
  • This PR adds the regex functionality to .toThrowDeveloperError() and .toBeRejectedWithDeveloperError()
  • .toThrowDeveloperError() didn't even allow for an expected string message so this also now provides that functionality
    • There were actually 3 tests trying to use this functionality with incorrect error messages which may have caused dev confusion in the future

Issue number and link

No issue

Testing plan

  • Do a project wide search for any .toThrowDeveloperError() or .toBeRejectedWithDeveloperError() call and focus that tests
    • Verify the tests still pass with no modifications
    • Test strings as the expected message, these must match the full string exactly
    • Test regex as the expected message, these can be a portion of the message or anything that will test as positive against the actual message

Author checklist

  • I have submitted a Contributor License Agreement
  • I have added my name to CONTRIBUTORS.md
  • I have updated CHANGES.md with a short summary of my change
  • I have added or updated unit tests to ensure consistent code coverage
  • I have updated the inline documentation, and included code examples where relevant
  • I have performed a self-review of my code

Copy link

Thank you for the pull request, @jjspace!

✅ We can confirm we have a CLA on file for you.

Copy link
Contributor

@ggetz ggetz left a comment

Choose a reason for hiding this comment

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

Thanks @jjspace! Should the testing guide be updated? Particularly, under Testing Exceptions, should the example be updated to include message text?

@jjspace
Copy link
Contributor Author

jjspace commented Dec 9, 2024

@ggetz good call, I've added a new tip for error messages

@ggetz
Copy link
Contributor

ggetz commented Dec 9, 2024

Awesome, thanks @jjspace!

@ggetz ggetz added this pull request to the merge queue Dec 9, 2024
Merged via the queue into main with commit a93e415 Dec 9, 2024
9 checks passed
@ggetz ggetz deleted the dev-error-matchers branch December 9, 2024 21:27
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.

2 participants