Skip to content

Commit

Permalink
Failing test for facebook#18657
Browse files Browse the repository at this point in the history
  • Loading branch information
acdlite committed Apr 17, 2020
1 parent a4b1e65 commit b7a0583
Showing 1 changed file with 49 additions and 0 deletions.
Expand Up @@ -3869,4 +3869,53 @@ describe('ReactSuspenseWithNoopRenderer', () => {
expect(root).toMatchRenderedOutput(<span prop="b" />);
});
});

it('regression: #18657', async () => {
const {useState} = React;

let setText;
function App() {
const [text, _setText] = useState('A');
setText = _setText;
return <AsyncText text={text} />;
}

const root = ReactNoop.createRoot();
await ReactNoop.act(async () => {
await resolveText('A');
root.render(
<Suspense fallback={<Text text="Loading..." />}>
<App />
</Suspense>,
);
});
expect(Scheduler).toHaveYielded(['A']);
expect(root).toMatchRenderedOutput(<span prop="A" />);

await ReactNoop.act(async () => {
setText('B');
Scheduler.unstable_runWithPriority(
Scheduler.unstable_IdlePriority,
() => {
setText('B');
},
);
// Suspend the first update. The second update doesn't run because it has
// Idle priority.
expect(Scheduler).toFlushAndYield(['Suspend! [B]', 'Loading...']);

// Commit the fallback. Now we'll try working on Idle.
jest.runAllTimers();

// It also suspends.
expect(Scheduler).toFlushAndYield(['Suspend! [B]']);
});

await ReactNoop.act(async () => {
setText('B');
await resolveText('B');
});
expect(Scheduler).toHaveYielded(['Promise resolved [B]', 'B']);
expect(root).toMatchRenderedOutput(<span prop="B" />);
});
});

0 comments on commit b7a0583

Please sign in to comment.