Skip to content

Commit 95030fb

Browse files
committed
chore: remove redundant string validation feature
1 parent 8b8c135 commit 95030fb

File tree

4 files changed

+11
-109
lines changed

4 files changed

+11
-109
lines changed

src/__tests__/render-string-validation.test.tsx

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,13 @@ afterEach(() => {
2424
});
2525

2626
test('should throw when rendering a string outside a text component', () => {
27-
expect(() =>
28-
render(<View>hello</View>, {
29-
unstable_validateStringsRenderedWithinText: true,
30-
}),
31-
).toThrow(
27+
expect(() => render(<View>hello</View>)).toThrow(
3228
`${VALIDATION_ERROR}. Detected attempt to render "hello" string within a <View> component.`,
3329
);
3430
});
3531

3632
test('should throw an error when rerendering with text outside of Text component', () => {
37-
render(<View />, {
38-
unstable_validateStringsRenderedWithinText: true,
39-
});
33+
render(<View />);
4034

4135
expect(() => screen.rerender(<View>hello</View>)).toThrow(
4236
`${VALIDATION_ERROR}. Detected attempt to render "hello" string within a <View> component.`,
@@ -58,9 +52,7 @@ const InvalidTextAfterPress = () => {
5852
};
5953

6054
test('should throw an error when strings are rendered outside Text', () => {
61-
render(<InvalidTextAfterPress />, {
62-
unstable_validateStringsRenderedWithinText: true,
63-
});
55+
render(<InvalidTextAfterPress />);
6456

6557
expect(() => fireEvent.press(screen.getByText('Show text'))).toThrow(
6658
`${VALIDATION_ERROR}. Detected attempt to render "text rendered outside text component" string within a <View> component.`,
@@ -73,23 +65,17 @@ test('should not throw for texts nested in fragments', () => {
7365
<Text>
7466
<>hello</>
7567
</Text>,
76-
{ unstable_validateStringsRenderedWithinText: true },
7768
),
7869
).not.toThrow();
7970
});
8071

81-
// test('should not throw if option validateRenderedString is false', () => {
82-
// expect(() => render(<View>hello</View>)).not.toThrow();
83-
// });
84-
8572
test(`should throw when one of the children is a text and the parent is not a Text component`, () => {
8673
expect(() =>
8774
render(
8875
<View>
8976
<Text>hello</Text>
9077
hello
9178
</View>,
92-
{ unstable_validateStringsRenderedWithinText: true },
9379
),
9480
).toThrow(
9581
`${VALIDATION_ERROR}. Detected attempt to render "hello" string within a <View> component.`,
@@ -102,17 +88,14 @@ test(`should throw when a string is rendered within a fragment rendered outside
10288
<View>
10389
<>hello</>
10490
</View>,
105-
{ unstable_validateStringsRenderedWithinText: true },
10691
),
10792
).toThrow(
10893
`${VALIDATION_ERROR}. Detected attempt to render "hello" string within a <View> component.`,
10994
);
11095
});
11196

11297
test('should throw if a number is rendered outside a text', () => {
113-
expect(() =>
114-
render(<View>0</View>, { unstable_validateStringsRenderedWithinText: true }),
115-
).toThrow(
98+
expect(() => render(<View>0</View>)).toThrow(
11699
`${VALIDATION_ERROR}. Detected attempt to render "0" string within a <View> component.`,
117100
);
118101
});
@@ -125,7 +108,6 @@ test('should throw with components returning string value not rendered in Text',
125108
<View>
126109
<Trans i18nKey="hello" />
127110
</View>,
128-
{ unstable_validateStringsRenderedWithinText: true },
129111
),
130112
).toThrow(
131113
`${VALIDATION_ERROR}. Detected attempt to render "hello" string within a <View> component.`,
@@ -138,7 +120,6 @@ test('should not throw with components returning string value rendered in Text',
138120
<Text>
139121
<Trans i18nKey="hello" />
140122
</Text>,
141-
{ unstable_validateStringsRenderedWithinText: true },
142123
),
143124
).not.toThrow();
144125
});
@@ -149,7 +130,6 @@ test('should throw when rendering string in a View in a Text', () => {
149130
<Text>
150131
<View>hello</View>
151132
</Text>,
152-
{ unstable_validateStringsRenderedWithinText: true },
153133
),
154134
).toThrow(
155135
`${VALIDATION_ERROR}. Detected attempt to render "hello" string within a <View> component.`,
@@ -175,7 +155,7 @@ const UseEffectComponent = () => {
175155
};
176156

177157
test('should render immediate setState in useEffect properly', async () => {
178-
render(<UseEffectComponent />, { unstable_validateStringsRenderedWithinText: true });
158+
render(<UseEffectComponent />);
179159

180160
expect(await screen.findByText('Text is visible')).toBeTruthy();
181161
});
@@ -195,9 +175,7 @@ const InvalidUseEffectComponent = () => {
195175
};
196176

197177
test('should throw properly for immediate setState in useEffect', () => {
198-
expect(() =>
199-
render(<InvalidUseEffectComponent />, { unstable_validateStringsRenderedWithinText: true }),
200-
).toThrow(
178+
expect(() => render(<InvalidUseEffectComponent />)).toThrow(
201179
`${VALIDATION_ERROR}. Detected attempt to render "Text is visible" string within a <View> component.`,
202180
);
203181
});

src/helpers/string-validation.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/render.tsx

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import * as React from 'react';
2-
import { Profiler } from 'react';
32
import act from './act';
43
import { addToCleanupQueue } from './cleanup';
54
import { getConfig } from './config';
65
import debugDeep, { DebugOptions } from './helpers/debug-deep';
76
import debugShallow from './helpers/debug-shallow';
87
import { configureHostComponentNamesIfNeeded } from './helpers/host-component-names';
9-
import { validateStringsRenderedWithinText } from './helpers/string-validation';
108
import { HostElement } from './renderer/host-element';
119
import { RenderResult as RendererResult } from './renderer/renderer';
1210
import { renderWithAct } from './render-act';
@@ -16,7 +14,6 @@ import { getQueriesForElement } from './within';
1614
export interface RenderOptions {
1715
wrapper?: React.ComponentType<any>;
1816
createNodeMock?: (element: React.ReactElement) => unknown;
19-
unstable_validateStringsRenderedWithinText?: boolean;
2017
}
2118

2219
export type RenderResult = ReturnType<typeof render>;
@@ -37,55 +34,17 @@ export function renderInternal<T>(
3734
component: React.ReactElement<T>,
3835
options?: RenderInternalOptions,
3936
) {
40-
const {
41-
wrapper: Wrapper,
42-
detectHostComponentNames = true,
43-
unstable_validateStringsRenderedWithinText,
44-
...restOptions
45-
} = options || {};
37+
const { wrapper: Wrapper, detectHostComponentNames = true, ...restOptions } = options || {};
4638

4739
if (detectHostComponentNames) {
4840
configureHostComponentNamesIfNeeded();
4941
}
5042

51-
if (unstable_validateStringsRenderedWithinText) {
52-
return renderWithStringValidation(component, {
53-
wrapper: Wrapper,
54-
...restOptions,
55-
});
56-
}
57-
5843
const wrap = (element: React.ReactElement) => (Wrapper ? <Wrapper>{element}</Wrapper> : element);
5944
const renderer = renderWithAct(wrap(component), restOptions);
6045
return buildRenderResult(renderer, wrap);
6146
}
6247

63-
function renderWithStringValidation<T>(
64-
component: React.ReactElement<T>,
65-
options: Omit<RenderOptions, 'unstable_validateStringsRenderedWithinText'> = {},
66-
) {
67-
let renderer: RendererResult;
68-
const { wrapper: Wrapper, ...testRendererOptions } = options ?? {};
69-
70-
const handleRender: React.ProfilerOnRenderCallback = (_, phase) => {
71-
if (renderer && phase === 'update') {
72-
validateStringsRenderedWithinText(renderer.toJSON());
73-
}
74-
};
75-
76-
const wrap = (element: React.ReactElement) => (
77-
<Profiler id="renderProfiler" onRender={handleRender}>
78-
{Wrapper ? <Wrapper>{element}</Wrapper> : element}
79-
</Profiler>
80-
);
81-
82-
renderer = renderWithAct(wrap(component), testRendererOptions);
83-
84-
validateStringsRenderedWithinText(renderer.toJSON());
85-
86-
return buildRenderResult(renderer, wrap);
87-
}
88-
8948
function buildRenderResult(
9049
renderer: RendererResult,
9150
wrap: (element: React.ReactElement) => JSX.Element,

typings/index.flow.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ declare type A11yRole =
5555

5656
declare type A11yState = {|
5757
disabled?: boolean,
58-
selected?: boolean,
59-
checked?: boolean | 'mixed',
60-
busy?: boolean,
61-
expanded?: boolean,
58+
selected ?: boolean,
59+
checked ?: boolean | 'mixed',
60+
busy ?: boolean,
61+
expanded ?: boolean,
6262
|};
6363

6464
declare type A11yValue = {
@@ -347,7 +347,6 @@ declare module '@testing-library/react-native' {
347347
declare interface RenderOptions {
348348
wrapper?: React.ComponentType<any>;
349349
createNodeMock?: (element: React.Element<any>) => any;
350-
unstable_validateStringsRenderedWithinText?: boolean;
351350
unstable_isConcurrent?: boolean;
352351
unstable_strictMode?: boolean;
353352
unstable_concurrentUpdatesByDefault?: boolean;

0 commit comments

Comments
 (0)