Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

RangeError: Invalid string length when toJSON is not used #1803

Unanswered
roni-castro-shipt asked this question in Q&A
Discussion options

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

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /