Skip to content

React-Native: Fix userEvent.setup() errors outside browser context #30831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025

Conversation

dannyhw
Copy link
Member

@dannyhw dannyhw commented Mar 17, 2025

Closes #

What I did

protect against calling userEvent setup when not in a supported context like react native

fixes the error causing the latest alpha to fail on react native

 (NOBRIDGE) ERROR  [TypeError: Cannot convert undefined value to object]

The error comes from testing library using window.navigator.clipboard and other browser specific things

Checklist for Contributors

Testing

tested by editing in node modules on my alpha 6 branch
storybookjs/react-native#699

I add the check in
node_modules/storybook/dist/test/preview.js

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This pull request has been released as version 0.0.0-pr-30831-sha-94c10a14. Try it out in a new sandbox by running npx storybook@0.0.0-pr-30831-sha-94c10a14 sandbox or in an existing project with npx storybook@0.0.0-pr-30831-sha-94c10a14 upgrade.

More information
Published version 0.0.0-pr-30831-sha-94c10a14
Triggered by @shilman
Repository storybookjs/storybook
Branch dannyhw/fix-userevent-not-callable-in-reactnative
Commit 94c10a14
Datetime Mon Mar 17 16:13:09 UTC 2025 (1742227989)
Workflow run 13904350719

To request a new release of this pull request, mention the @storybookjs/core team.

core team members can create a new canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=30831

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +80 to 82
if (globalThis.window && globalThis.HTMLElement) {
context.userEvent = instrument({ userEvent: userEvent.setup() }, { intercept: true }).userEvent;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider adding a fallback behavior or warning message when userEvent cannot be initialized in non-browser environments

@dannyhw dannyhw changed the title React-Native: Fix cannot call userEvent.setup errors outside the browser context (react native) React-Native: Fix calling userEvent.setup errors outside the browser context (react native) Mar 17, 2025
@dannyhw dannyhw requested a review from shilman March 17, 2025 15:59
Copy link

nx-cloud bot commented Mar 17, 2025

View your CI Pipeline Execution ↗ for commit 94c10a1.

Command Status Duration Result
nx affected -t check -c production --parallel=7 ✅ Succeeded 1m 30s View ↗
nx run-many -t build -c production --parallel=3 ✅ Succeeded 4m 28s View ↗

☁️ Nx Cloud last updated this comment at 2025-03-17 16:06:00 UTC

@shilman shilman changed the title React-Native: Fix calling userEvent.setup errors outside the browser context (react native) React-Native: Fix calling userEvent.setup errors outside the browser context Mar 17, 2025
@shilman shilman changed the title React-Native: Fix calling userEvent.setup errors outside the browser context React-Native: Fix userEvent.setup() errors outside browser context Mar 17, 2025
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

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

💯

@shilman shilman merged commit a12c488 into next Mar 17, 2025
61 of 70 checks passed
@shilman shilman deleted the dannyhw/fix-userevent-not-callable-in-reactnative branch March 17, 2025 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy