168
ops = [];
169
170
// This will abort the previous work and restart
171
+ ReactNoop.flushSync(() => ReactNoop.render(null));
172
ReactNoop.render(<Foo text="baz" />);
173
174
// Flush part of the new work
222
expect(ops).toEqual(['setState1']);
223
224
// This will abort the previous work and restart
225
+ ReactNoop.flushSync(() => ReactNoop.render(<Foo />));
226
inst.setState(
227
() => {
228
ops.push('setState2');
1879
);
1880
ReactNoop.flush();
1881
expect(ops).toEqual([
1882
+ 'ShowLocale {"locale":"sv"}',
1883
+ 'ShowBoth {"locale":"sv"}',
1884
'Intl {}',
1885
'ShowLocale {"locale":"en"}',
1886
'Router {}',
2652
'count:1, name:not brian',
2653
]);
2654
});
2655
+
2656
+ it('does not interrupt for update at same priority', () => {
2657
+ function Parent(props) {
2658
+ ReactNoop.yield('Parent: ' + props.step);
2659
+ return <Child step={props.step} />;
2660
+ }
2661
+
2662
+ function Child(props) {
2663
+ ReactNoop.yield('Child: ' + props.step);
2664
+ return null;
2665
+ }
2666
+
2667
+ ReactNoop.render(<Parent step={1} />);
2668
+ ReactNoop.flushThrough(['Parent: 1']);
2669
+
2670
+ // Interrupt at same priority
2671
+ ReactNoop.render(<Parent step={2} />);
2672
+
2673
+ expect(ReactNoop.flush()).toEqual(['Child: 1', 'Parent: 2', 'Child: 2']);
2674
+ });
2675
+
2676
+ it('does not interrupt for update at lower priority', () => {
2677
+ function Parent(props) {
2678
+ ReactNoop.yield('Parent: ' + props.step);
2679
+ return <Child step={props.step} />;
2680
+ }
2681
+
2682
+ function Child(props) {
2683
+ ReactNoop.yield('Child: ' + props.step);
2684
+ return null;
2685
+ }
2686
+
2687
+ ReactNoop.render(<Parent step={1} />);
2688
+ ReactNoop.flushThrough(['Parent: 1']);
2689
+
2690
+ // Interrupt at lower priority
2691
+ ReactNoop.expire(2000);
2692
+ ReactNoop.render(<Parent step={2} />);
2693
+
2694
+ expect(ReactNoop.flush()).toEqual(['Child: 1', 'Parent: 2', 'Child: 2']);
2695
+ });
2696
+
2697
+ it('does interrupt for update at higher priority', () => {
2698
+ function Parent(props) {
2699
+ ReactNoop.yield('Parent: ' + props.step);
2700
+ return <Child step={props.step} />;
2701
+ }
2702
+
2703
+ function Child(props) {
2704
+ ReactNoop.yield('Child: ' + props.step);
2705
+ return null;
2706
+ }
2707
+
2708
+ ReactNoop.render(<Parent step={1} />);
2709
+ ReactNoop.flushThrough(['Parent: 1']);
2710
+
2711
+ // Interrupt at higher priority
2712
+ expect(
2713
+ ReactNoop.flushSync(() => ReactNoop.render(<Parent step={2} />)),
2714
+ ).toEqual(['Parent: 2', 'Child: 2']);
2715
+
2716
+ expect(ReactNoop.flush()).toEqual([]);
2717
+ });
2718
});