Skip to content

Commit

Permalink
added a busyDelayMs/busyMinDurationMs test
Browse files Browse the repository at this point in the history
  • Loading branch information
lunaruan committed Oct 11, 2019
1 parent ab07c5a commit 7b7db2d
Showing 1 changed file with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2039,8 +2039,75 @@ describe('ReactHooksWithNoopRenderer', () => {
span('After... Pending: false'),
]);
});
});
it('delays showing loading state until after busyDelayMs + busyMinDurationMs', async () => {
let transition;
function App() {
const [show, setShow] = useState(false);
const [startTransition, isPending] = useTransition({
busyDelayMs: 1000,
busyMinDurationMs: 2000,
});
transition = () => {
startTransition(() => {
setShow(true);
});
};
return (
<Suspense
fallback={<Text text={`Loading... Pending: ${isPending}`} />}>
{show ? (
<AsyncText ms={2000} text={`After... Pending: ${isPending}`} />
) : (
<Text text={`Before... Pending: ${isPending}`} />
)}
</Suspense>
);
}
ReactNoop.render(<App />);
expect(Scheduler).toFlushAndYield(['Before... Pending: false']);
expect(ReactNoop.getChildren()).toEqual([
span('Before... Pending: false'),
]);

act(() => {
Scheduler.unstable_runWithPriority(
Scheduler.unstable_UserBlockingPriority,
transition,
);
});
Scheduler.unstable_advanceTime(1000);
await advanceTimers(1000);
expect(Scheduler).toHaveYielded([
'Before... Pending: true',
'Suspend! [After... Pending: false]',
'Loading... Pending: false',
]);
expect(ReactNoop.getChildren()).toEqual([
span('Before... Pending: true'),
]);

Scheduler.unstable_advanceTime(1000);
await advanceTimers(1000);
expect(Scheduler).toHaveYielded([
'Promise resolved [After... Pending: false]',
]);
expect(Scheduler).toFlushAndYield(['After... Pending: false']);
expect(ReactNoop.getChildren()).toEqual([
span('Before... Pending: true'),
]);

Scheduler.unstable_advanceTime(1000);
await advanceTimers(1000);
expect(ReactNoop.getChildren()).toEqual([
span('Before... Pending: true'),
]);
Scheduler.unstable_advanceTime(250);
await advanceTimers(250);
expect(ReactNoop.getChildren()).toEqual([
span('After... Pending: false'),
]);
});
});
describe('useDeferredValue', () => {
it('defers text value until specified timeout', async () => {
function TextBox({text}) {
Expand Down

0 comments on commit 7b7db2d

Please sign in to comment.