feat(expect): support async extended matchers
This allows extended matchers in expect to return either ExtendMatchResult or Promise<ExtendMatchResult>
This changes provides additional possibilities for custom matchers, like implementing a expect(value).toBeResolved() matcher.
Example:
const { promise, resolve } = Promise.withResolvers<void>();
await expect(promise).not.toBeResolved();
resolve();
await expect(promise).toBeResolved();
// NB: this is different from expect(promise).resolves.toBe()
// Here we test the actual promise state, not its resolved value
This is just an example, but it can be used for any custom matcher that requires async operations on the right side (for example one could image matching agains dynamically fetched files, database query results, etc.)
Side note: While this PR doesn't address specifically the following issues, the example (in the diff of the test file) shows how to implement a matcher to test promise states
- #3759
- #5727
Needs rebase after #6807 for lint issues
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 94.23%. Comparing base (08061ad) to head (34282b7).
Additional details and impacted files
@@ Coverage Diff @@
## main #6806 +/- ##
=======================================
Coverage 94.23% 94.23%
=======================================
Files 590 590
Lines 42811 42824 +13
Branches 6788 6793 +5
=======================================
+ Hits 40342 40356 +14
+ Misses 2419 2418 -1
Partials 50 50
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Needs rebase after #6807 for lint issues