react-native-reanimated: Snapshots excessively large or failing with `Invalid string length`
Description
Since Reanimated v3.16.0, snapshots using @testing-library/react-native have been breaking. In some cases, the snapshot size has increased drastically, going from less than 1 KB to over 250 MB. In other cases, snapshots fail to generate, throwing an Invalid string length error.
v3.15.5
PASS ./ComponentTwo.test.tsx
› 1 snapshot written.
PASS ./ComponentOne.test.tsx
› 1 snapshot written.
Snapshot Summary
› 2 snapshots written from 2 test suites.
Test Suites: 2 passed, 2 total
Tests: 2 passed, 2 total
Snapshots: 2 written, 2 total
Time: 1.938 s, estimated 22 s
➜ ls -lh
total 16
-rw-r--r--@ 1 brianvalente staff 586B Oct 28 16:22 ComponentOne.test.tsx.snap
-rw-r--r--@ 1 brianvalente staff 925B Oct 28 16:22 ComponentTwo.test.tsx.snap
v3.16.1
PASS ./ComponentOne.test.tsx (6.267 s)
› 1 snapshot written.
FAIL ./ComponentTwo.test.tsx (9.18 s)
● ComponentTwo › should pass
RangeError: Invalid string length
6 | it("should pass", () => {
7 | const rendered = render(<ComponentTwo />).toJSON();
> 8 | expect(rendered).toMatchSnapshot();
| ^
9 | });
10 | })
11 |
at printElement (node_modules/jest-snapshot/node_modules/pretty-format/build/plugins/lib/markup.js:105:36)
at Object.toMatchSnapshot (ComponentTwo.test.tsx:8:26)
Snapshot Summary
› 1 snapshot written from 1 test suite.
Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 failed, 1 passed, 2 total
Snapshots: 1 written, 1 total
Time: 9.404 s
➜ ls -lh
total 537280
-rw-r--r--@ 1 brianvalente staff 262M Oct 28 16:23 ComponentOne.test.tsx.snap
Steps to reproduce
- Clone demo repo
- Install dependencies
- Run
npm run test
Snack or a link to a repository
https://github.com/BrianValente/reanimated-jest-snapshot-issue-demo
Reanimated version
3.6.1
React Native version
0.74.5
Platforms
Android, iOS, macOS, Web
JavaScript runtime
Hermes
Workflow
Expo Dev Client
Architecture
Paper (Old Architecture)
Build type
Other (please specify)
Device
None
Device model
No response
Acknowledgements
Yes
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 12
- Comments: 21
Commits related to this issue
- feat: react-native-reanimated@3.x not support jest snap (https://github.com/software-mansion/react-native-reanimated/issues/6645) — committed to ant-design/ant-design-mobile-rn by 1uokun 2 years ago
- Merge pull request #1393 from ant-design/5.3.0 * feat: Modal add useModal(#1383) * feat: Picker support modalType(#1383) * feat: Carousel support onScrollAnimationEnd * fix:[Form] fix Requir... — committed to ant-design/ant-design-mobile-rn by 1uokun 2 years ago
- fix: Jest snapshots (#7372) ## Summary Adding the feature of Inline Style testing #6400 in Jest broke snapshots, since it pushed the whole `this.props.style` object to `jestInlineStyles` object. `th... — committed to software-mansion/react-native-reanimated by tjzel 2 years ago
- fix: Jest snapshots (#7372) Adding the feature of Inline Style testing #6400 in Jest broke snapshots, since it pushed the whole `this.props.style` object to `jestInlineStyles` object. `this.props.sty... — committed to software-mansion/react-native-reanimated by tjzel 2 years ago
- fix: Jest snapshots (#7372) Adding the feature of Inline Style testing #6400 in Jest broke snapshots, since it pushed the whole `this.props.style` object to `jestInlineStyles` object. `this.props.sty... — committed to software-mansion/react-native-reanimated by tjzel 2 years ago
- fix: Jest snapshots (#7372) Adding the feature of Inline Style testing #6400 in Jest broke snapshots, since it pushed the whole `this.props.style` object to `jestInlineStyles` object. `this.props.sty... — committed to software-mansion/react-native-reanimated by tjzel 2 years ago
An alternative patch that worked here:
Applying @Grohden 's patch works! However, I found that tests that use
expect(component).toHaveAnimatedStyle(...)would fail. Here’s an updated patch that fixes thisHere is happening with reanimated version 3.16.x, while on 3.15.x is not happening
Hey @ilteoood,
Same here. This unblocks me, and now I will be able to upgrade to newest
expo-sdk52Thanks!
Update: unfortunately I have Android build errors on version 3.15, so stuck again 😦