Skip to content

feat: export UserEventInstance type - #1967

Merged
mdjastrzebski merged 2 commits into
callstack:mainfrom
psjostrom:export-user-event-instance-type
Dec 1, 2026
Merged

mdjastrzebski merged 2 commits into
callstack:mainfrom
psjostrom:export-user-event-instance-type

Conversation

@psjostrom

@psjostrom psjostrom commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Export the UserEventInstance type from the package root, next to UserEventConfig.
  • setup() declares UserEventInstance as its return type, and the setup() docs show it.
  • src/user-event/index.ts re-exports both interfaces with export type. A plain export made Babel emit a getter for each interface in dist/user-event/index.js, and the getter returns undefined.

We have a test helper that returns { screen, user }. To name the type of user, it imports from @testing-library/react-native/dist/user-event/setup, and that path broke when v14 moved build/ to dist/. The other option is ReturnType<typeof userEvent.setup>. #1091 exported RenderResult and RenderHookResult for the same reason.

Test plan

  • yarn validate passes, with 955 tests.
  • In an app on 14.1.0, import type { RenderResult, UserEventInstance } from '@testing-library/react-native' fails with TS2305. With this branch's build in node_modules, the same import typechecks, and the app's tests that use the helper pass.
  • dist/user-event/index.js from yarn build has no UserEventConfig or UserEventInstance export.

`userEvent.setup()` returns a `UserEventInstance`, but the package exports only
`UserEventConfig`. A helper that returns or receives the instance had to import
the type from `dist/user-event/setup` or write `ReturnType<typeof userEvent.setup>`.
`RenderResult` and `RenderHookResult` are exported for the same reason.

`setup()` now declares `UserEventInstance` as its return type, so the exported
type cannot drift from what `setup()` returns. `src/user-event/index.ts`
re-exports both interfaces with `export type`. A plain `export` made Babel emit
a getter for each interface in `dist/user-event/index.js` that returns
`undefined`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@psjostrom
psjostrom marked this pull request as ready for review November 26, 2026 15:39
@mdjastrzebski
mdjastrzebski merged commit 4344e2f into callstack:main Dec 1, 2026
35 checks passed
@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.60%. Comparing base (5a05c26) to head (b4266c5).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1967      +/-   ##
==========================================
+ Coverage   98.56%   98.60%   +0.03%     
==========================================
  Files          87       88       +1     
  Lines        1748     1786      +38     
  Branches      479      491      +12     
==========================================
+ Hits         1723     1761      +38     
  Misses         24       24              
  Partials        1        1              

☔ 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.

@mdjastrzebski

Copy link
Copy Markdown
Member

Released in v14.1.1 🎉

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