Add Promise as a child test to Flight fixture (#28778)
Sebastian Silbermann committed
Apr 8, 2024 at 17:06 UTC
e63918d2cd53b03c19119b475e116d1b45fd0f84
2 files changed
+12
-1
fixtures/flight/__tests__/__e2e__/smoke.test.js
+3
-1
@@ -13,7 +13,9 @@ test('smoke test', async ({page}) => {
13
pageErrors.push(error.stack);
14
});
15
await page.goto('/');
16
- await expect(page.locator('h1')).toHaveText('Hello World');
16
+ await expect(page.getByTestId('promise-as-a-child-test')).toHaveText(
17
+ 'Promise as a child hydrates without errors: deferred text'
18
+ );
19
20
await expect(consoleErrors).toEqual([]);
21
await expect(pageErrors).toEqual([]);
fixtures/flight/src/App.js
+9
@@ -19,6 +19,10 @@ import {like, greet, increment} from './actions.js';
19
20
import {getServerState} from './ServerState.js';
21
22
+const promisedText = new Promise(resolve =>
23
+ setTimeout(() => resolve('deferred text'), 100)
24
+);
25
+
26
export default async function App() {
27
const res = await fetch('http://localhost:3001/todos');
28
const todos = await res.json();
@@ -32,6 +36,11 @@ export default async function App() {
36
<body>
37
<Container>
38
<h1>{getServerState()}</h1>
39
+ <React.Suspense fallback={null}>
40
+ <div data-testid="promise-as-a-child-test">
41
+ Promise as a child hydrates without errors: {promisedText}
42
+ </div>
43
+ </React.Suspense>
44
<Counter incrementAction={increment} />
45
<Counter2 incrementAction={increment} />
46
<Counter3 incrementAction={increment} />