Skip to content

Commit 3039c6f

Browse files
committed
Failing test for false positive warning
1 parent e15542e commit 3039c6f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,4 +1366,35 @@ describe('ReactHooks', () => {
13661366
),
13671367
).toThrow('Hello');
13681368
});
1369+
1370+
// Regression test for https://github.com/facebook/react/issues/14790
1371+
it('does not fire a false positive warning when suspending', async () => {
1372+
const {Suspense, useState, useRef} = React;
1373+
1374+
let wasSuspended = false;
1375+
function trySuspend() {
1376+
if (!wasSuspended) {
1377+
throw new Promise(resolve => {
1378+
wasSuspended = true;
1379+
resolve();
1380+
});
1381+
}
1382+
}
1383+
1384+
function Child() {
1385+
React.useState();
1386+
trySuspend();
1387+
return 'hello';
1388+
}
1389+
1390+
const Wrapper = React.memo(Child);
1391+
const root = ReactTestRenderer.create(
1392+
<Suspense fallback="loading">
1393+
<Wrapper />
1394+
</Suspense>,
1395+
);
1396+
expect(root).toMatchRenderedOutput('loading');
1397+
await Promise.resolve();
1398+
expect(root).toMatchRenderedOutput('hello');
1399+
});
13691400
});

0 commit comments

Comments
 (0)