Skip to content

Conversation

lowlighter
Copy link
Contributor

@lowlighter lowlighter commented Aug 28, 2025

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

Needs rebase after #6807 for lint issues

Copy link

codecov bot commented Aug 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ 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           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lowlighter lowlighter marked this pull request as ready for review August 28, 2025 03:57
@lowlighter lowlighter requested a review from kt3k as a code owner August 28, 2025 03:57
@lowlighter
Copy link
Contributor Author

Needs rebase after #6807 for lint issues

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

Successfully merging this pull request may close these issues.

2 participants