Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

fix: jest.mock() is not allowed to reference any out-of-scope variables #18 #41

Closed

Conversation

anantoghosh
Copy link
Contributor

@anantoghosh anantoghosh commented Oct 6, 2022

This PR fixes two issues with mock variable names.

ReferenceError: /sss/node_modules/@ionic/react-test-utils/dist/mocks/mockIonicReact.js: The module factory of `jest.mock()` is not allowed to reference any out-of-scope variables.
    Invalid variable access: react_1
ReferenceError: /sss/@ionic/react-test-utils/dist/mocks/mockIonicReact.js: The module factory of `jest.mock()` is not allowed to reference any out-of-scope variables.
    Invalid variable access: useIonPicker_mock_1

The variable names are derived from the imported file name instead of the imported variable name.

  1. Current build imports IonInput from @ionic/react which gets the var name as react_1 which is out of scope of the jest mock which jest will complain about.
    This PR uses the IonInput from the rest variable which is in the mock scope.

  2. The import mockUseIonPicker gets the name from the filename instead of the export variable name in the build causing it to lose the mock in front of it. This PR renames the file to include mock in it.

fixes #18

@liamdebeasi
Copy link
Contributor

Thank you very much for the PR! We appreciate the work you put into resolving this. I ended up creating separate PRs so each fix shows up as a separate commit, but I gave you co-author credit in af458a8 and e0d76d0.

These fixes should be available in the next release of Ionic React Test Utils. I am going to close this since the other PRs resolved the issues.

@anantoghosh
Copy link
Contributor Author

Thank you!

@anantoghosh anantoghosh deleted the fix/reference-out-of-scope branch October 13, 2022 11:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: Error in mockIonicReact: "Invalid variable access: react_1"
2 participants