-
Notifications
You must be signed in to change notification settings - Fork 279
RangeError: Invalid string length when toJSON is not used #1803
Unanswered
roni-castro-shipt
asked this question in
Q&A
-
Is there any alternative to tests like the one below that does not use toJSON
, but .props
, and fails when using ref?
I used this app config + added "resolutions": { "react-is": "19.0.0" }
to check if it would solve that, like mentioned here, but it does not solve that problem.
Example component with ref
import React, { useRef } from 'react'; import { ScrollView, View } from 'react-native'; export const ViewWithRefFailsSnapshot = () => { const scrollViewRef = useRef(null); return ( <View> <View testID={'my-view'} > <ScrollView ref={scrollViewRef}></ScrollView> </View> </View> ); }; export default ViewWithRefFailsSnapshot;
Example of test that will generate huge snapshots
import React from 'react'; import { render } from '@testing-library/react-native'; import ViewWithRefFailsSnapshot from '../App'; describe('ViewWithRefFailsSnapshot', () => { it('renders default when tier status is summit star', () => { const wrapper = render(<ViewWithRefFailsSnapshot />); expect(wrapper.getByTestId('my-view').props).toMatchSnapshot(); }); });
Snapshot generated
Screenshot 2025年08月01日 at 16 02 24
It generates a snapshot with 4MB, and 71363 lines. If I make it more complex, like the real case I have, it would throw RangeError: Invalid string length
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment