Skip to content

fix: restore shipping mocks with react-native package #51525

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

Conversation

mdjastrzebski
Copy link
Contributor

@mdjastrzebski mdjastrzebski commented May 22, 2025

Summary:

PR #50784 added __mocks__ directory to npm package exclude list in package.json files.

That change broke the Jest preset that relies on RefreshControl mock being held in __mocks__:

  .mock('../Libraries/Components/RefreshControl/RefreshControl', () => ({
    __esModule: true,
    default: jest.requireActual(
      '../Libraries/Components/RefreshControl/__mocks__/RefreshControlMock',
    ).default,
  }))

From user's perspective importing RefreshControl in Jest tests breaks the test suits attempting it:

Cannot find module '../Libraries/Components/RefreshControl/__mocks__/RefreshControlMock' from'node_modules/react-native/jest/setup.js'

Note before #50784 __mocks__ folders were not excluded from react-native package.

Changelog:

[GENERAL] [FIXED] - Restore shipping Jest mocks with react-native package.

Test Plan:

Check if '../Libraries/Components/RefreshControl/__mocks__/RefreshControlMock' is present in the npm package.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels May 22, 2025
@facebook-github-bot
Copy link
Contributor

@rshest has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@huntie
Copy link
Member

huntie commented May 22, 2025

@mdjastrzebski Great find 😮, thanks!

I've opened an alternative fix, if that's okay 🙏🏻 — relocates this mock as source code inside our Jest preset.

#51530

@mdjastrzebski
Copy link
Contributor Author

@huntie I like your solution even better. Based on the jest/setup.js this one the only location with __mocks__ in the path.

@huntie huntie closed this May 22, 2025
huntie added a commit to huntie/react-native that referenced this pull request May 22, 2025
Summary:
Aims to give us CI coverage of React Native's Jest preset, preventing future bugs like facebook#51525.

Changes:
- Add a basic "it renders" Jest test to helloworld
- Add "Run Helloworld tests" step to `test-ios-helloworld` job in CI
- Also convert helloworld's `App.tsx` to TypeScript, as easiest way to unblock Jest JSX behaviour.

Changelog: [Internal]

Differential Revision: D75218901
huntie added a commit to huntie/react-native that referenced this pull request May 22, 2025
Summary:
Pull Request resolved: facebook#51534

Aims to give us CI coverage of React Native's Jest preset, preventing future bugs like facebook#51525.

Changes:
- Add a basic "it renders" Jest test to helloworld
- Add "Run Helloworld tests" step to `test-ios-helloworld` job in CI
- Also convert helloworld's `App.tsx` to TypeScript, as easiest way to unblock Jest JSX behaviour.

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D75218901
facebook-github-bot pushed a commit that referenced this pull request May 22, 2025
Summary:
Pull Request resolved: #51534

Aims to give us CI coverage of React Native's Jest preset, preventing future bugs like #51525.

Changes:
- Add a basic "it renders" Jest test to helloworld
- Add "Run Helloworld tests" step to `test-ios-helloworld` job in CI
- Also convert helloworld's `App.tsx` to TypeScript, as easiest way to unblock Jest JSX behaviour.

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D75218901

fbshipit-source-id: 601155c59c4483696971df4c29d51549d97f49f2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants