670
// Destroying the first child shouldn't prevent the passive effect from
671
// being executed
672
ReactNoop.render([passive]);
673
- expect(Scheduler).toHaveYielded(['Passive effect']);
674
- expect(Scheduler).toFlushAndYield([]);
673
+ expect(Scheduler).toFlushAndYield(['Passive effect']);
674
expect(ReactNoop.getChildren()).toEqual([span('Passive')]);
675
676
// (No effects are left to flush.)
775
ReactNoop.render(<Counter count={1} />, () =>
776
Scheduler.yieldValue('Sync effect'),
777
);
779
- expect(Scheduler).toHaveYielded([
778
+ expect(Scheduler).toFlushAndYieldThrough([
779
// The previous effect flushes before the reconciliation
780
'Committed state when effect was fired: 0',
781
+ 1,
782
+ 'Sync effect',
783
]);
783
- expect(Scheduler).toFlushAndYieldThrough([1, 'Sync effect']);
784
expect(ReactNoop.getChildren()).toEqual([span(1)]);
785
786
ReactNoop.flushPassiveEffects();
849
ReactNoop.render(<Counter count={1} />, () =>
850
Scheduler.yieldValue('Sync effect'),
851
);
852
- expect(Scheduler).toHaveYielded(['Schedule update [0]']);
853
- expect(Scheduler).toFlushAndYieldThrough(['Count: 0']);
852
+ expect(Scheduler).toFlushAndYieldThrough([
853
+ 'Schedule update [0]',
854
+ 'Count: 0',
855
+ ]);
856
expect(ReactNoop.getChildren()).toEqual([span('Count: (empty)')]);
857
858
expect(Scheduler).toFlushAndYieldThrough(['Sync effect']);
864
expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
865
});
866
865
- it('flushes serial effects before enqueueing work', () => {
867
+ it('flushes passive effects when flushing discrete updates', () => {
868
let _updateCount;
869
function Counter(props) {
870
const [count, updateCount] = useState(0);
882
expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
883
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
884
883
- // Enqueuing this update forces the passive effect to be flushed --
885
+ // A discrete event forces the passive effect to be flushed --
886
// updateCount(1) happens first, so 2 wins.
885
- act(() => _updateCount(2));
887
+ ReactNoop.interactiveUpdates(() => {
888
+ act(() => _updateCount(2));
889
+ });
890
expect(Scheduler).toHaveYielded(['Will set count to 1']);
891
expect(Scheduler).toFlushAndYield(['Count: 2']);
892
expect(ReactNoop.getChildren()).toEqual([span('Count: 2')]);
893
});
894
891
- it('flushes serial effects before enqueueing work (with tracing)', () => {
895
+ it('flushes passive effects when flushing discrete updates (with tracing)', () => {
896
const onInteractionScheduledWorkCompleted = jest.fn();
897
const onWorkCanceled = jest.fn();
898
SchedulerTracing.unstable_subscribe({
933
934
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(0);
935
932
- // Enqueuing this update forces the passive effect to be flushed --
936
+ // A discrete event forces the passive effect to be flushed --
937
// updateCount(1) happens first, so 2 wins.
934
- act(() => _updateCount(2));
938
+ ReactNoop.interactiveUpdates(() => {
939
+ act(() => _updateCount(2));
940
+ });
941
expect(Scheduler).toHaveYielded(['Will set count to 1']);
942
expect(Scheduler).toFlushAndYield(['Count: 2']);
943
expect(ReactNoop.getChildren()).toEqual([span('Count: 2')]);
1478
ReactNoop.render(<Counter count={1} />, () =>
1479
Scheduler.yieldValue('Sync effect'),
1480
);
1475
- expect(Scheduler).toHaveYielded(['Mount normal [current: 0]']);
1481
expect(Scheduler).toFlushAndYieldThrough([
1482
+ 'Mount normal [current: 0]',
1483
'Unmount layout [current: 0]',
1484
'Mount layout [current: 1]',
1485
'Sync effect',