Skip to content

Feat async extended matchers#7213

Open
lowlighter wants to merge 3 commits into
denoland:mainfrom
lowlighter:feat-async-extended-matchers
Open

Feat async extended matchers#7213
lowlighter wants to merge 3 commits into
denoland:mainfrom
lowlighter:feat-async-extended-matchers

Conversation

@lowlighter

@lowlighter lowlighter commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

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

This is a reopen of #6806, i mistakenly closed it by deleting my fork

@github-actions github-actions Bot added the expect label Jul 5, 2026
@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.84%. Comparing base (3b390d0) to head (64c2974).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7213   +/-   ##
=======================================
  Coverage   94.84%   94.84%           
=======================================
  Files         617      618    +1     
  Lines       51674    51690   +16     
  Branches     9350     9355    +5     
=======================================
+ Hits        49008    49024   +16     
  Misses       2121     2121           
  Partials      545      545           

☔ View full report in Codecov by Harness.
📢 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.

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