Open stevoland opened 8 months ago
Bump, seeing similar issues
Just experienced the same issue after upgrading react-native
from 0.72.12
to 0.73.8
Here are some other versions I'm using. Hope it should help for the investigation
"@testing-library/jest-native": "5.4.3",
"@testing-library/react-hooks": "8.0.1",
"@testing-library/react-native": "12.4.4",
"babel-jest": "29.7.0",
"jest": "29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-junit": "13.0.0",
"react-test-renderer": "18.2.0",
Just experienced the same issue after upgrading
react-native
from0.72.12
to0.73.8
Here are some other versions I'm using. Hope it should help for the investigation
"@testing-library/jest-native": "5.4.3", "@testing-library/react-hooks": "8.0.1", "@testing-library/react-native": "12.4.4", "babel-jest": "29.7.0", "jest": "29.7.0", "jest-environment-jsdom": "^29.7.0", "jest-junit": "13.0.0", "react-test-renderer": "18.2.0",
I was able to fix this type of issue with migration jest.resetAllMocks
to jest.clearAllMocks
I'm also running into this and greatly appreciate y'all mentioning the workaround of popping the below into the jest-setup.ts
as that worked around it for us. Switching from reset to clear didn't make any difference for us though.
const { Switch } = require('react-native');
🙇
Description
Bit of a niche one: We see failing unit tests after upgrading 0.72.10 --> 0.73.4:
Real-world manifestation occurs in tests calling
jest.resetAllMocks()
with a setup using v1 reanimated mock https://github.com/software-mansion/react-native-reanimated/blob/main/mock.jsSome info from debugging:
a) the mock requires
Image
from'react-native'
(among other things but Image causes the issue) b) the test callsjest.resetAllMocks()
c)@testing-library/react-native
rendersSwitch
withreact-test-renderer
in each test which blows up here: https://github.com/callstack/react-native-testing-library/blob/main/src/helpers/host-component-names.tsx#L37(There may be other (mocked) components affected by the issue)
See reduced test case in this commit https://github.com/stevoland/RNTest/commit/9841d46ce0c03cde9749c36ddd58a8b2bb96930a
Our workaround is to first get a reference to Switch in the
setupFiles
https://github.com/stevoland/RNTest/blob/9841d46ce0c03cde9749c36ddd58a8b2bb96930a/jest-setup.js#L2 (Possibly relevant that this has to be a require and not an import statement)Thanks
Steps to reproduce
git clone https://github.com/stevoland/RNTest yarn install yarn test
React Native Version
0.73.4
Affected Platforms
Other (please specify)
Output of
npx react-native info
Stacktrace or Logs
Reproducer
https://github.com/stevoland/RNTest/tree/jest-reset-switch-repro
Screenshots and Videos
No response