Skip to content

Commit 0441c84

Browse files
committed
.
1 parent ea48684 commit 0441c84

File tree

1 file changed

+11
-50
lines changed

1 file changed

+11
-50
lines changed

src/__tests__/react-suspense.test.tsx

Lines changed: 11 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import TestRenderer, { type ReactTestRenderer } from 'react-test-renderer';
44

55
import { configure, renderAsync, screen, within } from '..';
66

7+
const isReact19 = React.version.startsWith('19.');
8+
const testGateReact19 = isReact19 ? test : test.skip;
9+
710
configure({
811
asyncUtilTimeout: 5000,
912
});
@@ -16,75 +19,33 @@ function wait(delay: number) {
1619
);
1720
}
1821

19-
function Suspendable<T>({ promise }: { promise: Promise<T> }) {
22+
function Suspending<T>({ promise }: { promise: Promise<T> }) {
2023
React.use(promise);
21-
return <View testID="test" />;
24+
return <View testID="view" />;
2225
}
2326

24-
test('render supports components which can suspend', async () => {
27+
testGateReact19('render supports components which can suspend', async () => {
2528
await renderAsync(
2629
<View>
2730
<React.Suspense fallback={<View testID="fallback" />}>
28-
<Suspendable promise={wait(100)} />
31+
<Suspending promise={wait(100)} />
2932
</React.Suspense>
3033
</View>,
3134
);
3235

3336
expect(screen.getByTestId('fallback')).toBeOnTheScreen();
34-
expect(await screen.findByTestId('test')).toBeOnTheScreen();
35-
});
36-
37-
test('react test renderer supports components which can suspend', async () => {
38-
let renderer: ReactTestRenderer;
39-
40-
// eslint-disable-next-line require-await
41-
await React.act(async () => {
42-
renderer = TestRenderer.create(
43-
<View>
44-
<React.Suspense fallback={<View testID="fallback" />}>
45-
<Suspendable promise={wait(100)} />
46-
</React.Suspense>
47-
</View>,
48-
);
49-
});
50-
51-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
52-
const view = within(renderer!.root);
53-
54-
expect(view.getByTestId('fallback')).toBeDefined();
55-
expect(await view.findByTestId('test')).toBeDefined();
56-
});
57-
58-
test('react test renderer supports components which can suspend 500', async () => {
59-
let renderer: ReactTestRenderer;
60-
61-
// eslint-disable-next-line require-await
62-
await React.act(async () => {
63-
renderer = TestRenderer.create(
64-
<View>
65-
<React.Suspense fallback={<View testID="fallback" />}>
66-
<Suspendable promise={wait(500)} />
67-
</React.Suspense>
68-
</View>,
69-
);
70-
});
71-
72-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
73-
const view = within(renderer!.root);
74-
75-
expect(view.getByTestId('fallback')).toBeDefined();
76-
expect(await view.findByTestId('test')).toBeDefined();
37+
expect(await screen.findByTestId('view')).toBeOnTheScreen();
7738
});
7839

79-
test('react test renderer supports components which can suspend 1000ms', async () => {
40+
testGateReact19('react test renderer supports components which can suspend', async () => {
8041
let renderer: ReactTestRenderer;
8142

8243
// eslint-disable-next-line require-await
8344
await React.act(async () => {
8445
renderer = TestRenderer.create(
8546
<View>
8647
<React.Suspense fallback={<View testID="fallback" />}>
87-
<Suspendable promise={wait(1000)} />
48+
<Suspending promise={wait(100)} />
8849
</React.Suspense>
8950
</View>,
9051
);
@@ -94,5 +55,5 @@ test('react test renderer supports components which can suspend 1000ms', async (
9455
const view = within(renderer!.root);
9556

9657
expect(view.getByTestId('fallback')).toBeDefined();
97-
expect(await view.findByTestId('test', undefined, { timeout: 5000 })).toBeDefined();
58+
expect(await view.findByTestId('view')).toBeDefined();
9859
});

0 commit comments

Comments
 (0)