Skip to content

fix: match ESM matcher declarations to named runtime exports - #746

Open
rishilifts wants to merge 5 commits into
testing-library:mainfrom
rishilifts:fix-744-esm-matcher-types
Open

rishilifts wants to merge 5 commits into
testing-library:mainfrom
rishilifts:fix-744-esm-matcher-types

Conversation

@rishilifts

Copy link
Copy Markdown

Fixes #744.

What: Give the ./matchers import condition an ESM declaration file with named exports. Keep the existing CommonJS declaration for the require condition.

Why: A dynamic import currently has a phantom default in its type, although the ESM module only exports named matchers. This makes Bun's expect.extend(await import(...)) fail type-checking.

How: Reuse the standalone matcher signatures in a .d.mts declaration. Added Bundler and Node16 type fixtures for static and dynamic imports, absence of default, the complete matcher key set, the exported interface and both toHaveClass overloads.

Validation:

  • Both new configurations fail with the original import declaration and pass with the fix.
  • All existing Jest, Jest globals, Vitest and Bun type tests pass.
  • 632 tests / 64 suites and 118 unchanged snapshots pass; coverage is 100%.
  • Full lint, formatting and build pass.
  • Built ESM module's 49 runtime names match the declaration names; npm pack includes the new declaration.

The test run needs FORCE_COLOR=1 in this environment because diagnostic snapshots contain ANSI colors. Without it, the same 100 snapshot mismatches occur on the unchanged baseline; no snapshots were updated.

Checklist:

  • Tests
  • Updated Type Definitions
  • Ready to be merged after review
  • Documentation: N/A, no API change

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.

./matchers types declare a default export that the ESM build does not have

1 participant