Skip to content

fix: accept StoryContext's userEvent.setup() instance in I.init - #15

Merged
Guria merged 3 commits into
mainfrom
t3/f9152f8b
Oct 8, 2026
Merged

Guria merged 3 commits into
mainfrom
t3/f9152f8b

Conversation

@Guria

@Guria Guria commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

StoryContext.userEvent is ReturnType<typeof userEvent.setup> (keyboard(): Promise<void>). UserEvent was picked from the direct API (keyboard(): Promise<System>), so passing a real context to I.init failed typecheck once @testing-library/user-event types resolved; consumers had to cast.

  • UserEvent types only clear/click/keyboard/tab/type, taking the setup-instance parameters and returning Promise<unknown>. Both the instance and the direct API are assignable. Still renderer-agnostic, type-only import from the storybook peer.
  • test/context.test.ts asserts with expectTypeOf(...).toExtend<StoryContext>() that Storybook's StoryContext and StoryContextForLoaders (with a custom renderer and args, since StepFunction is invariant in them) and a direct-userEvent context are accepted. Without the fix, typecheck reports 3 errors.
  • Minor changeset (breaking type change: UserEvent methods return Promise<unknown>, so keyboard() no longer resolves to System). README doesn't mention the type, so it's unchanged.

pnpm run check passes.

[Claude Code (Opus 5.5) — t3cody]

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility for initializing with Storybook contexts that use either userEvent.setup() or the direct userEvent API.
    • Updated supported user-event method types to accept setup-instance arguments and return promises.
  • Tests
    • Added type checks for story and loader contexts, including custom and default context types.

Guria added 2 commits October 8, 2026 11:44
StoryContext.userEvent is a setup() instance (keyboard(): Promise<void>);
UserEvent was picked from the direct API (keyboard(): Promise<System>),
so a real context failed to typecheck. Type only the called methods,
with Promise<unknown> returns.
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e919e625-f3f6-4867-9df1-03e0fe11a894
📥 Commits

Reviewing files that changed from the base of the PR and between fb984ed and daa9844.

📒 Files selected for processing (3)
  • .changeset/accept-setup-user-event.md
  • src/context.ts
  • test/context.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The UserEvent type now uses method parameters from a userEvent.setup() instance and declares Promise<unknown> returns. Compile-time checks cover Storybook story and loader contexts, including contexts that use the direct userEvent API.

Changes

Context typing

Layer / File(s) Summary
UserEvent typing and compatibility checks
src/context.ts, test/context.test.ts, .changeset/accept-setup-user-event.md
UserEvent maps supported methods to parameters from a setup instance and declares Promise<unknown> returns. Compile-time checks cover parameterized and default Storybook contexts, loader contexts, and the direct userEvent API. The changeset records the patch and describes the accepted context forms.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to daa98

The context typing change has no identified merge-blocking issue. Normal checks remain appropriate before merging.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: allowing I.init to accept a Storybook StoryContext userEvent.setup() instance.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/kahraman@15

commit: feb8804

@Guria
Guria requested a balanced review from Copilot October 8, 2026 11:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The exported UserEvent return type introduces an unacknowledged source-breaking API change.

1 open finding
What changed in this PR

Updates actor context typing to accept Storybook setup-based and direct user-event APIs.

Changes:

  • Defines the minimal user-event methods required by the actor.
  • Adds compile-time compatibility tests.
  • Adds a patch changeset.
File Description
src/​context.ts Broadens accepted user-event implementations.
test/​context.test.ts Adds Storybook context compatibility checks.
.changeset/​accept-setup-user-event.md Documents the release change.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread src/context.ts
UserEvent methods now return Promise<unknown>; keyboard() lost its
System result type.
@Guria
Guria merged commit 86e3c77 into main Oct 8, 2026
4 checks passed
@Guria
Guria deleted the t3/f9152f8b branch October 8, 2026 11:56
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