-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
fix(jest/setup): fix circular dependencies in mockModal #32964
fix(jest/setup): fix circular dependencies in mockModal #32964
Conversation
Base commit: 3d1d4ee |
Base commit: 3d1d4ee |
@lunaleaps has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
…lar dependencies in mockModal
a1c4575
to
bd6d83b
Compare
@lunaleaps @yungsters Thanks for your reviews. I took your comments into account and updated the PR. |
@lunaleaps has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
This pull request was successfully merged by @AntoineDoubovetzky in 507b05f. When will my fix make it into a release? | Upcoming Releases |
Summary: Fixes #32939 It appears there is circular dependencies on the Modal component that causes the modalMock function to be an empty object. Removing the import fixes the issue. I don't know yet why this is not happening when executing the test suite inside `Modal-test.js` but I will investigate this later. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [General] [Fixed] - Fix error "mockModal is not a function" Pull Request resolved: #32964 Test Plan: On a newly initiated project using react-native 0.67.1 I created a ModalComponent: ``` import React from 'react'; import {Modal, Text} from 'react-native'; export const ModalComponent = () => { return ( <Modal visible> <Text>Test</Text> </Modal> ); }; ``` and a ModalComponent.test.tsx: ``` import 'react-native'; import React from 'react'; import {ModalComponent} from '../ModalComponent'; // Note: test renderer must be required after react-native. import renderer from 'react-test-renderer'; it('renders correctly', () => { renderer.create(<ModalComponent />); }); ``` Running the test throws the error "TypeError: mockModal is not a function". After modifying the mockModal inside node_modules/react-native/jest/mockModal.js it works correctly. Reviewed By: christophpurrer Differential Revision: D33771136 Pulled By: lunaleaps fbshipit-source-id: c09ada8d2f864f5568b3379616a6cace9fb9921e
Summary
Fixes #32939
It appears there is circular dependencies on the Modal component that causes the modalMock function to be an empty object. Removing the import fixes the issue.
I don't know yet why this is not happening when executing the test suite inside
Modal-test.js
but I will investigate this later.Changelog
[General] [Fixed] - Fix error "mockModal is not a function"
Test Plan
On a newly initiated project using react-native 0.67.1 I created a ModalComponent:
and a ModalComponent.test.tsx:
Running the test throws the error "TypeError: mockModal is not a function".
After modifying the mockModal inside node_modules/react-native/jest/mockModal.js it works correctly.