Skip to content

Conversation

@yungsters
Copy link
Contributor

Summary:
Refactors the default mocks initialized in packages/react-native/jest/setup.js so that each mock is defined in its own file.

This provides several benefits, including:

  • The ability to use import statements without worrying about eager initialization of dependencies before globals is setup.
  • The ability to verify mocks export the same types as the actual module, using a new Flow-typed mock helper function.
  • The ergonomic of implementing mocks with more complex logic, without having to split them out into a separate module (e.g. mockModal, mockScrollView).

As part of this migration, I also fixed any minor discrepancies to match the actual type definition. For more involved discrepancies (e.g. missing methods), I added type suppressions for now to minimize breaking changes.

Changelog:
[General][Changed] - Improved default mocking for Jest unit tests.

Differential Revision: D75575421

@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. fb-exported labels May 29, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D75575421

yungsters added a commit to yungsters/react-native that referenced this pull request May 29, 2025
Summary:

Refactors the default mocks initialized in `packages/react-native/jest/setup.js` so that each mock is defined in its own file.

This provides several benefits, including:

- The ability to use `import` statements without worrying about eager initialization of dependencies before `globals` is setup.
- The ability to verify mocks export the same types as the actual module, using a new Flow-typed `mock` helper function.
- The ergonomic of implementing mocks with more complex logic, without having to split them out into a separate module (e.g. `mockModal`, `mockScrollView`).

As part of this migration, I also fixed any minor discrepancies to match the actual type definition. For more involved discrepancies (e.g. missing methods), I added type suppressions for now to minimize breaking changes.

Changelog:
[General][Changed] - Improved default mocking for Jest unit tests.

Differential Revision: D75575421
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D75575421

yungsters added a commit to yungsters/react-native that referenced this pull request May 29, 2025
Summary:

Refactors the default mocks initialized in `packages/react-native/jest/setup.js` so that each mock is defined in its own file.

This provides several benefits, including:

- The ability to use `import` statements without worrying about eager initialization of dependencies before `globals` is setup.
- The ability to verify mocks export the same types as the actual module, using a new Flow-typed `mock` helper function.
- The ergonomic of implementing mocks with more complex logic, without having to split them out into a separate module (e.g. `mockModal`, `mockScrollView`).

As part of this migration, I also fixed any minor discrepancies to match the actual type definition. For more involved discrepancies (e.g. missing methods), I added type suppressions for now to minimize breaking changes.

Changelog:
[General][Changed] - Improved default mocking for Jest unit tests.

Differential Revision: D75575421
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D75575421

yungsters added a commit to yungsters/react-native that referenced this pull request May 29, 2025
Summary:

Refactors the default mocks initialized in `packages/react-native/jest/setup.js` so that each mock is defined in its own file.

This provides several benefits, including:

- The ability to use `import` statements without worrying about eager initialization of dependencies before `globals` is setup.
- The ability to verify mocks export the same types as the actual module, using a new Flow-typed `mock` helper function.
- The ergonomic of implementing mocks with more complex logic, without having to split them out into a separate module (e.g. `mockModal`, `mockScrollView`).

As part of this migration, I also fixed any minor discrepancies to match the actual type definition. For more involved discrepancies (e.g. missing methods), I added type suppressions for now to minimize breaking changes.

Changelog:
[General][Changed] - Improved default mocking for Jest unit tests.

Differential Revision: D75575421
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D75575421

yungsters added a commit to yungsters/react-native that referenced this pull request May 29, 2025
Summary:

Refactors the default mocks initialized in `packages/react-native/jest/setup.js` so that each mock is defined in its own file.

This provides several benefits, including:

- The ability to use `import` statements without worrying about eager initialization of dependencies before `globals` is setup.
- The ability to verify mocks export the same types as the actual module, using a new Flow-typed `mock` helper function.
- The ergonomic of implementing mocks with more complex logic, without having to split them out into a separate module (e.g. `mockModal`, `mockScrollView`).

As part of this migration, I also fixed any minor discrepancies to match the actual type definition. For more involved discrepancies (e.g. missing methods), I added type suppressions for now to minimize breaking changes.

Changelog:
[General][Changed] - Improved default mocking for Jest unit tests.

Differential Revision: D75575421
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D75575421

yungsters added a commit to yungsters/react-native that referenced this pull request May 29, 2025
Summary:

Refactors the default mocks initialized in `packages/react-native/jest/setup.js` so that each mock is defined in its own file.

This provides several benefits, including:

- The ability to use `import` statements without worrying about eager initialization of dependencies before `globals` is setup.
- The ability to verify mocks export the same types as the actual module, using a new Flow-typed `mock` helper function.
- The ergonomic of implementing mocks with more complex logic, without having to split them out into a separate module (e.g. `mockModal`, `mockScrollView`).

As part of this migration, I also fixed any minor discrepancies to match the actual type definition. For more involved discrepancies (e.g. missing methods), I added type suppressions for now to minimize breaking changes.

Changelog:
[General][Changed] - Improved default mocking for Jest unit tests.

Differential Revision: D75575421
yungsters added a commit to yungsters/react-native that referenced this pull request May 29, 2025
Summary:

Refactors the default mocks initialized in `packages/react-native/jest/setup.js` so that each mock is defined in its own file.

This provides several benefits, including:

- The ability to use `import` statements without worrying about eager initialization of dependencies before `globals` is setup.
- The ability to verify mocks export the same types as the actual module, using a new Flow-typed `mock` helper function.
- The ergonomic of implementing mocks with more complex logic, without having to split them out into a separate module (e.g. `mockModal`, `mockScrollView`).

As part of this migration, I also fixed any minor discrepancies to match the actual type definition. For more involved discrepancies (e.g. missing methods), I added type suppressions for now to minimize breaking changes.

Changelog:
[General][Changed] - Improved default mocking for Jest unit tests.

Differential Revision: D75575421
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D75575421

Summary:
Pull Request resolved: facebook#51669

Refactors the default mocks initialized in `packages/react-native/jest/setup.js` so that each mock is defined in its own file.

This provides several benefits, including:

- The ability to use `import` statements without worrying about eager initialization of dependencies before `globals` is setup.
- The ability to verify mocks export the same types as the actual module, using a new Flow-typed `mock` helper function.
- The ergonomic of implementing mocks with more complex logic, without having to split them out into a separate module (e.g. `mockModal`, `mockScrollView`).

As part of this migration, I also fixed any minor discrepancies to match the actual type definition. For more involved discrepancies (e.g. missing methods), I added type suppressions for now to minimize breaking changes.

Changelog:
[General][Changed] - Improved default mocking for Jest unit tests.

Differential Revision: D75575421
yungsters added a commit to yungsters/react-native that referenced this pull request May 29, 2025
Summary:
Pull Request resolved: facebook#51669

Refactors the default mocks initialized in `packages/react-native/jest/setup.js` so that each mock is defined in its own file.

This provides several benefits, including:

- The ability to use `import` statements without worrying about eager initialization of dependencies before `globals` is setup.
- The ability to verify mocks export the same types as the actual module, using a new Flow-typed `mock` helper function.
- The ergonomic of implementing mocks with more complex logic, without having to split them out into a separate module (e.g. `mockModal`, `mockScrollView`).

As part of this migration, I also fixed any minor discrepancies to match the actual type definition. For more involved discrepancies (e.g. missing methods), I added type suppressions for now to minimize breaking changes.

Changelog:
[General][Changed] - Improved default mocking for Jest unit tests.

Differential Revision: D75575421
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D75575421

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label May 29, 2025
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 1fd9508.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @yungsters in 1fd9508

When will my fix make it into a release? | How to file a pick request?

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. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants