Skip to content

Commit

Permalink
Failing test for false positive warning
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Feb 11, 2019
1 parent e15542e commit 3039c6f
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1366,4 +1366,35 @@ describe('ReactHooks', () => {
),
).toThrow('Hello');
});

// Regression test for https://github.com/facebook/react/issues/14790
it('does not fire a false positive warning when suspending', async () => {
const {Suspense, useState, useRef} = React;

let wasSuspended = false;
function trySuspend() {
if (!wasSuspended) {
throw new Promise(resolve => {
wasSuspended = true;
resolve();
});
}
}

function Child() {
React.useState();
trySuspend();
return 'hello';
}

const Wrapper = React.memo(Child);
const root = ReactTestRenderer.create(
<Suspense fallback="loading">
<Wrapper />
</Suspense>,
);
expect(root).toMatchRenderedOutput('loading');
await Promise.resolve();
expect(root).toMatchRenderedOutput('hello');
});
});

0 comments on commit 3039c6f

Please sign in to comment.