Skip to content

Commit

Permalink
Port tests to old API
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Mar 27, 2019
1 parent cd5b895 commit 297165f
Showing 1 changed file with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1886,41 +1886,42 @@ describe('ReactHooksWithNoopRenderer', () => {
// This reducer closes over a value from props. If the reducer is not
// properly updated, the eager reducer will compare to an old value
// and bail out incorrectly.
Scheduler.yieldValue('Reducer: ' + count);
ReactNoop.yield('Reducer: ' + count);
return count;
}, -1);
useEffect(
() => {
Scheduler.yieldValue('Effect: ' + count);
ReactNoop.yield('Effect: ' + count);
dispatch();
},
[count],
);
Scheduler.yieldValue('Render: ' + state);
return count;
ReactNoop.yield('Render: ' + state);
return <span prop={count} />;
}

ReactNoop.render(<App />);
expect(Scheduler).toFlushAndYield([
'Render: -1',
expect(ReactNoop.flush()).toEqual(['Render: -1']);
ReactNoop.flushPassiveEffects();
expect(ReactNoop.flush()).toEqual([
'Effect: 1',
'Reducer: 1',
'Reducer: 1',
'Render: 1',
]);
expect(ReactNoop).toMatchRenderedOutput('1');
expect(ReactNoop.getChildren()).toEqual([span(1)]);

act(() => {
setCounter(2);
});
expect(Scheduler).toFlushAndYield([
expect(ReactNoop.flush()).toEqual([
'Render: 1',
'Effect: 2',
'Reducer: 2',
'Reducer: 2',
'Render: 2',
]);
expect(ReactNoop).toMatchRenderedOutput('2');
expect(ReactNoop.getChildren()).toEqual([span(2)]);
});

it('should update latest rendered reducer when a preceding state receives a render phase update', () => {
Expand All @@ -1936,23 +1937,23 @@ describe('ReactHooksWithNoopRenderer', () => {
setStep(step + 1);
}

Scheduler.yieldValue(`Step: ${step}, Shadow: ${shadow}`);
return shadow;
ReactNoop.yield(`Step: ${step}, Shadow: ${shadow}`);
return <span prop={shadow} />;
}

ReactNoop.render(<App />);
expect(Scheduler).toFlushAndYield([
expect(ReactNoop.flush()).toEqual([
'Step: 0, Shadow: 0',
'Step: 1, Shadow: 0',
'Step: 2, Shadow: 0',
'Step: 3, Shadow: 0',
'Step: 4, Shadow: 0',
'Step: 5, Shadow: 0',
]);
expect(ReactNoop).toMatchRenderedOutput('0');
expect(ReactNoop.getChildren()).toEqual([span(0)]);

act(() => dispatch());
expect(Scheduler).toFlushAndYield(['Step: 5, Shadow: 5']);
expect(ReactNoop).toMatchRenderedOutput('5');
expect(ReactNoop.flush()).toEqual(['Step: 5, Shadow: 5']);
expect(ReactNoop.getChildren()).toEqual([span(5)]);
});
});

0 comments on commit 297165f

Please sign in to comment.