Skip to content

Commit

Permalink
Add tests for forwardRef too
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Feb 12, 2019
1 parent 1bda3bb commit 3a53a84
Showing 1 changed file with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ describe('ReactHooks', () => {
});

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

let wasSuspended = false;
Expand Down Expand Up @@ -1397,4 +1397,66 @@ describe('ReactHooks', () => {
await Promise.resolve();
expect(root).toMatchRenderedOutput('hello');
});

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

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

function render(props, ref) {
React.useState();
trySuspend();
return 'hello';
}

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

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

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

function render(props, ref) {
React.useState();
trySuspend();
return 'hello';
}

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

0 comments on commit 3a53a84

Please sign in to comment.