61
});
62
expect(root).toMatchRenderedOutput('1, 1');
63
});
64
-
65
- test('flushes passive effects synchronously when they are the result of a sync render', async () => {
66
- function App() {
67
- useEffect(() => {
68
- Scheduler.unstable_yieldValue('Effect');
69
- }, []);
70
- return <Text text="Child" />;
71
- }
72
-
73
- const root = ReactNoop.createRoot();
74
- await ReactNoop.act(async () => {
75
- ReactNoop.flushSync(() => {
76
- root.render(<App />);
77
- });
78
- expect(Scheduler).toHaveYielded([
79
- 'Child',
80
- // Because the pending effect was the result of a sync update, calling
81
- // flushSync should flush it.
82
- 'Effect',
83
- ]);
84
- expect(root).toMatchRenderedOutput('Child');
85
- });
86
- });
87
-
88
- test('do not flush passive effects synchronously in legacy mode', async () => {
89
- function App() {
90
- useEffect(() => {
91
- Scheduler.unstable_yieldValue('Effect');
92
- }, []);
93
- return <Text text="Child" />;
94
- }
95
-
96
- const root = ReactNoop.createLegacyRoot();
97
- await ReactNoop.act(async () => {
98
- ReactNoop.flushSync(() => {
99
- root.render(<App />);
100
- });
101
- expect(Scheduler).toHaveYielded([
102
- 'Child',
103
- // Because we're in legacy mode, we shouldn't have flushed the passive
104
- // effects yet.
105
- ]);
106
- expect(root).toMatchRenderedOutput('Child');
107
- });
108
- // Effect flushes after paint.
109
- expect(Scheduler).toHaveYielded(['Effect']);
110
- });
111
-
112
- test("do not flush passive effects synchronously when they aren't the result of a sync render", async () => {
113
- function App() {
114
- useEffect(() => {
115
- Scheduler.unstable_yieldValue('Effect');
116
- }, []);
117
- return <Text text="Child" />;
118
- }
119
-
120
- const root = ReactNoop.createRoot();
121
- await ReactNoop.act(async () => {
122
- root.render(<App />);
123
- expect(Scheduler).toFlushUntilNextPaint([
124
- 'Child',
125
- // Because the passive effect was not the result of a sync update, it
126
- // should not flush before paint.
127
- ]);
128
- expect(root).toMatchRenderedOutput('Child');
129
- });
130
- // Effect flushes after paint.
131
- expect(Scheduler).toHaveYielded(['Effect']);
132
- });
64
});