@samitouri / QOS-React-2 / commits / 11ac10b44e

Port error boundaries test to yieldValue (#18558)

Sebastian Markbåge committed Apr 9, 2020 at 11:13 UTC 11ac10b44e9371b258bbf13faffd0dde5a7c0d0e
1 file changed +352 -240
packages/react-dom/src/__tests__/ReactErrorBoundaries-test.internal.js
+352 -240
@@ -14,10 +14,9 @@ let React;
14 let ReactDOM;
15 let act;
16 let ReactFeatureFlags;
17 +let Scheduler;
18
19 describe('ReactErrorBoundaries', () => {
19 - let log;
20 -
20 let BrokenConstructor;
21 let BrokenComponentWillMount;
22 let BrokenComponentDidMount;
@@ -46,158 +45,207 @@ describe('ReactErrorBoundaries', () => {
45 ReactDOM = require('react-dom');
46 React = require('react');
47 act = require('react-dom/test-utils').act;
49 -
50 - log = [];
48 + Scheduler = require('scheduler');
49
50 BrokenConstructor = class extends React.Component {
51 constructor(props) {
52 super(props);
55 - log.push('BrokenConstructor constructor [!]');
53 + Scheduler.unstable_yieldValue('BrokenConstructor constructor [!]');
54 throw new Error('Hello');
55 }
56 render() {
59 - log.push('BrokenConstructor render');
57 + Scheduler.unstable_yieldValue('BrokenConstructor render');
58 return <div>{this.props.children}</div>;
59 }
60 UNSAFE_componentWillMount() {
63 - log.push('BrokenConstructor componentWillMount');
61 + Scheduler.unstable_yieldValue('BrokenConstructor componentWillMount');
62 }
63 componentDidMount() {
66 - log.push('BrokenConstructor componentDidMount');
64 + Scheduler.unstable_yieldValue('BrokenConstructor componentDidMount');
65 }
66 UNSAFE_componentWillReceiveProps() {
69 - log.push('BrokenConstructor componentWillReceiveProps');
67 + Scheduler.unstable_yieldValue(
68 + 'BrokenConstructor componentWillReceiveProps',
69 + );
70 }
71 UNSAFE_componentWillUpdate() {
72 - log.push('BrokenConstructor componentWillUpdate');
72 + Scheduler.unstable_yieldValue('BrokenConstructor componentWillUpdate');
73 }
74 componentDidUpdate() {
75 - log.push('BrokenConstructor componentDidUpdate');
75 + Scheduler.unstable_yieldValue('BrokenConstructor componentDidUpdate');
76 }
77 componentWillUnmount() {
78 - log.push('BrokenConstructor componentWillUnmount');
78 + Scheduler.unstable_yieldValue('BrokenConstructor componentWillUnmount');
79 }
80 };
81
82 BrokenComponentWillMount = class extends React.Component {
83 constructor(props) {
84 super(props);
85 - log.push('BrokenComponentWillMount constructor');
85 + Scheduler.unstable_yieldValue('BrokenComponentWillMount constructor');
86 }
87 render() {
88 - log.push('BrokenComponentWillMount render');
88 + Scheduler.unstable_yieldValue('BrokenComponentWillMount render');
89 return <div>{this.props.children}</div>;
90 }
91 UNSAFE_componentWillMount() {
92 - log.push('BrokenComponentWillMount componentWillMount [!]');
92 + Scheduler.unstable_yieldValue(
93 + 'BrokenComponentWillMount componentWillMount [!]',
94 + );
95 throw new Error('Hello');
96 }
97 componentDidMount() {
96 - log.push('BrokenComponentWillMount componentDidMount');
98 + Scheduler.unstable_yieldValue(
99 + 'BrokenComponentWillMount componentDidMount',
100 + );
101 }
102 UNSAFE_componentWillReceiveProps() {
99 - log.push('BrokenComponentWillMount componentWillReceiveProps');
103 + Scheduler.unstable_yieldValue(
104 + 'BrokenComponentWillMount componentWillReceiveProps',
105 + );
106 }
107 UNSAFE_componentWillUpdate() {
102 - log.push('BrokenComponentWillMount componentWillUpdate');
108 + Scheduler.unstable_yieldValue(
109 + 'BrokenComponentWillMount componentWillUpdate',
110 + );
111 }
112 componentDidUpdate() {
105 - log.push('BrokenComponentWillMount componentDidUpdate');
113 + Scheduler.unstable_yieldValue(
114 + 'BrokenComponentWillMount componentDidUpdate',
115 + );
116 }
117 componentWillUnmount() {
108 - log.push('BrokenComponentWillMount componentWillUnmount');
118 + Scheduler.unstable_yieldValue(
119 + 'BrokenComponentWillMount componentWillUnmount',
120 + );
121 }
122 };
123
124 BrokenComponentDidMount = class extends React.Component {
125 constructor(props) {
126 super(props);
115 - log.push('BrokenComponentDidMount constructor');
127 + Scheduler.unstable_yieldValue('BrokenComponentDidMount constructor');
128 }
129 render() {
118 - log.push('BrokenComponentDidMount render');
130 + Scheduler.unstable_yieldValue('BrokenComponentDidMount render');
131 return <div>{this.props.children}</div>;
132 }
133 UNSAFE_componentWillMount() {
122 - log.push('BrokenComponentDidMount componentWillMount');
134 + Scheduler.unstable_yieldValue(
135 + 'BrokenComponentDidMount componentWillMount',
136 + );
137 }
138 componentDidMount() {
125 - log.push('BrokenComponentDidMount componentDidMount [!]');
139 + Scheduler.unstable_yieldValue(
140 + 'BrokenComponentDidMount componentDidMount [!]',
141 + );
142 throw new Error('Hello');
143 }
144 UNSAFE_componentWillReceiveProps() {
129 - log.push('BrokenComponentDidMount componentWillReceiveProps');
145 + Scheduler.unstable_yieldValue(
146 + 'BrokenComponentDidMount componentWillReceiveProps',
147 + );
148 }
149 UNSAFE_componentWillUpdate() {
132 - log.push('BrokenComponentDidMount componentWillUpdate');
150 + Scheduler.unstable_yieldValue(
151 + 'BrokenComponentDidMount componentWillUpdate',
152 + );
153 }
154 componentDidUpdate() {
135 - log.push('BrokenComponentDidMount componentDidUpdate');
155 + Scheduler.unstable_yieldValue(
156 + 'BrokenComponentDidMount componentDidUpdate',
157 + );
158 }
159 componentWillUnmount() {
138 - log.push('BrokenComponentDidMount componentWillUnmount');
160 + Scheduler.unstable_yieldValue(
161 + 'BrokenComponentDidMount componentWillUnmount',
162 + );
163 }
164 };
165
166 BrokenComponentWillReceiveProps = class extends React.Component {
167 constructor(props) {
168 super(props);
145 - log.push('BrokenComponentWillReceiveProps constructor');
169 + Scheduler.unstable_yieldValue(
170 + 'BrokenComponentWillReceiveProps constructor',
171 + );
172 }
173 render() {
148 - log.push('BrokenComponentWillReceiveProps render');
174 + Scheduler.unstable_yieldValue('BrokenComponentWillReceiveProps render');
175 return <div>{this.props.children}</div>;
176 }
177 UNSAFE_componentWillMount() {
152 - log.push('BrokenComponentWillReceiveProps componentWillMount');
178 + Scheduler.unstable_yieldValue(
179 + 'BrokenComponentWillReceiveProps componentWillMount',
180 + );
181 }
182 componentDidMount() {
155 - log.push('BrokenComponentWillReceiveProps componentDidMount');
183 + Scheduler.unstable_yieldValue(
184 + 'BrokenComponentWillReceiveProps componentDidMount',
185 + );
186 }
187 UNSAFE_componentWillReceiveProps() {
158 - log.push(
188 + Scheduler.unstable_yieldValue(
189 'BrokenComponentWillReceiveProps componentWillReceiveProps [!]',
190 );
191 throw new Error('Hello');
192 }
193 UNSAFE_componentWillUpdate() {
164 - log.push('BrokenComponentWillReceiveProps componentWillUpdate');
194 + Scheduler.unstable_yieldValue(
195 + 'BrokenComponentWillReceiveProps componentWillUpdate',
196 + );
197 }
198 componentDidUpdate() {
167 - log.push('BrokenComponentWillReceiveProps componentDidUpdate');
199 + Scheduler.unstable_yieldValue(
200 + 'BrokenComponentWillReceiveProps componentDidUpdate',
201 + );
202 }
203 componentWillUnmount() {
170 - log.push('BrokenComponentWillReceiveProps componentWillUnmount');
204 + Scheduler.unstable_yieldValue(
205 + 'BrokenComponentWillReceiveProps componentWillUnmount',
206 + );
207 }
208 };
209
210 BrokenComponentWillUpdate = class extends React.Component {
211 constructor(props) {
212 super(props);
177 - log.push('BrokenComponentWillUpdate constructor');
213 + Scheduler.unstable_yieldValue('BrokenComponentWillUpdate constructor');
214 }
215 render() {
180 - log.push('BrokenComponentWillUpdate render');
216 + Scheduler.unstable_yieldValue('BrokenComponentWillUpdate render');
217 return <div>{this.props.children}</div>;
218 }
219 UNSAFE_componentWillMount() {
184 - log.push('BrokenComponentWillUpdate componentWillMount');
220 + Scheduler.unstable_yieldValue(
221 + 'BrokenComponentWillUpdate componentWillMount',
222 + );
223 }
224 componentDidMount() {
187 - log.push('BrokenComponentWillUpdate componentDidMount');
225 + Scheduler.unstable_yieldValue(
226 + 'BrokenComponentWillUpdate componentDidMount',
227 + );
228 }
229 UNSAFE_componentWillReceiveProps() {
190 - log.push('BrokenComponentWillUpdate componentWillReceiveProps');
230 + Scheduler.unstable_yieldValue(
231 + 'BrokenComponentWillUpdate componentWillReceiveProps',
232 + );
233 }
234 UNSAFE_componentWillUpdate() {
193 - log.push('BrokenComponentWillUpdate componentWillUpdate [!]');
235 + Scheduler.unstable_yieldValue(
236 + 'BrokenComponentWillUpdate componentWillUpdate [!]',
237 + );
238 throw new Error('Hello');
239 }
240 componentDidUpdate() {
197 - log.push('BrokenComponentWillUpdate componentDidUpdate');
241 + Scheduler.unstable_yieldValue(
242 + 'BrokenComponentWillUpdate componentDidUpdate',
243 + );
244 }
245 componentWillUnmount() {
200 - log.push('BrokenComponentWillUpdate componentWillUnmount');
246 + Scheduler.unstable_yieldValue(
247 + 'BrokenComponentWillUpdate componentWillUnmount',
248 + );
249 }
250 };
251
@@ -207,30 +255,42 @@ describe('ReactErrorBoundaries', () => {
255 };
256 constructor(props) {
257 super(props);
210 - log.push('BrokenComponentDidUpdate constructor');
258 + Scheduler.unstable_yieldValue('BrokenComponentDidUpdate constructor');
259 }
260 render() {
213 - log.push('BrokenComponentDidUpdate render');
261 + Scheduler.unstable_yieldValue('BrokenComponentDidUpdate render');
262 return <div>{this.props.children}</div>;
263 }
264 UNSAFE_componentWillMount() {
217 - log.push('BrokenComponentDidUpdate componentWillMount');
265 + Scheduler.unstable_yieldValue(
266 + 'BrokenComponentDidUpdate componentWillMount',
267 + );
268 }
269 componentDidMount() {
220 - log.push('BrokenComponentDidUpdate componentDidMount');
270 + Scheduler.unstable_yieldValue(
271 + 'BrokenComponentDidUpdate componentDidMount',
272 + );
273 }
274 UNSAFE_componentWillReceiveProps() {
223 - log.push('BrokenComponentDidUpdate componentWillReceiveProps');
275 + Scheduler.unstable_yieldValue(
276 + 'BrokenComponentDidUpdate componentWillReceiveProps',
277 + );
278 }
279 UNSAFE_componentWillUpdate() {
226 - log.push('BrokenComponentDidUpdate componentWillUpdate');
280 + Scheduler.unstable_yieldValue(
281 + 'BrokenComponentDidUpdate componentWillUpdate',
282 + );
283 }
284 componentDidUpdate() {
229 - log.push('BrokenComponentDidUpdate componentDidUpdate [!]');
285 + Scheduler.unstable_yieldValue(
286 + 'BrokenComponentDidUpdate componentDidUpdate [!]',
287 + );
288 throw new Error(this.props.errorText);
289 }
290 componentWillUnmount() {
233 - log.push('BrokenComponentDidUpdate componentWillUnmount');
291 + Scheduler.unstable_yieldValue(
292 + 'BrokenComponentDidUpdate componentWillUnmount',
293 + );
294 }
295 };
296
@@ -240,29 +300,41 @@ describe('ReactErrorBoundaries', () => {
300 };
301 constructor(props) {
302 super(props);
243 - log.push('BrokenComponentWillUnmount constructor');
303 + Scheduler.unstable_yieldValue('BrokenComponentWillUnmount constructor');
304 }
305 render() {
246 - log.push('BrokenComponentWillUnmount render');
306 + Scheduler.unstable_yieldValue('BrokenComponentWillUnmount render');
307 return <div>{this.props.children}</div>;
308 }
309 UNSAFE_componentWillMount() {
250 - log.push('BrokenComponentWillUnmount componentWillMount');
310 + Scheduler.unstable_yieldValue(
311 + 'BrokenComponentWillUnmount componentWillMount',
312 + );
313 }
314 componentDidMount() {
253 - log.push('BrokenComponentWillUnmount componentDidMount');
315 + Scheduler.unstable_yieldValue(
316 + 'BrokenComponentWillUnmount componentDidMount',
317 + );
318 }
319 UNSAFE_componentWillReceiveProps() {
256 - log.push('BrokenComponentWillUnmount componentWillReceiveProps');
320 + Scheduler.unstable_yieldValue(
321 + 'BrokenComponentWillUnmount componentWillReceiveProps',
322 + );
323 }
324 UNSAFE_componentWillUpdate() {
259 - log.push('BrokenComponentWillUnmount componentWillUpdate');
325 + Scheduler.unstable_yieldValue(
326 + 'BrokenComponentWillUnmount componentWillUpdate',
327 + );
328 }
329 componentDidUpdate() {
262 - log.push('BrokenComponentWillUnmount componentDidUpdate');
330 + Scheduler.unstable_yieldValue(
331 + 'BrokenComponentWillUnmount componentDidUpdate',
332 + );
333 }
334 componentWillUnmount() {
265 - log.push('BrokenComponentWillUnmount componentWillUnmount [!]');
335 + Scheduler.unstable_yieldValue(
336 + 'BrokenComponentWillUnmount componentWillUnmount [!]',
337 + );
338 throw new Error(this.props.errorText);
339 }
340 };
@@ -271,30 +343,40 @@ describe('ReactErrorBoundaries', () => {
343 constructor(props) {
344 super(props);
345 this.state = {error: null};
274 - log.push('BrokenComponentWillMountErrorBoundary constructor');
346 + Scheduler.unstable_yieldValue(
347 + 'BrokenComponentWillMountErrorBoundary constructor',
348 + );
349 }
350 render() {
351 if (this.state.error) {
278 - log.push('BrokenComponentWillMountErrorBoundary render error');
352 + Scheduler.unstable_yieldValue(
353 + 'BrokenComponentWillMountErrorBoundary render error',
354 + );
355 return <div>Caught an error: {this.state.error.message}.</div>;
356 }
281 - log.push('BrokenComponentWillMountErrorBoundary render success');
357 + Scheduler.unstable_yieldValue(
358 + 'BrokenComponentWillMountErrorBoundary render success',
359 + );
360 return <div>{this.props.children}</div>;
361 }
362 UNSAFE_componentWillMount() {
285 - log.push(
363 + Scheduler.unstable_yieldValue(
364 'BrokenComponentWillMountErrorBoundary componentWillMount [!]',
365 );
366 throw new Error('Hello');
367 }
368 componentDidMount() {
291 - log.push('BrokenComponentWillMountErrorBoundary componentDidMount');
369 + Scheduler.unstable_yieldValue(
370 + 'BrokenComponentWillMountErrorBoundary componentDidMount',
371 + );
372 }
373 componentWillUnmount() {
294 - log.push('BrokenComponentWillMountErrorBoundary componentWillUnmount');
374 + Scheduler.unstable_yieldValue(
375 + 'BrokenComponentWillMountErrorBoundary componentWillUnmount',
376 + );
377 }
378 static getDerivedStateFromError(error) {
297 - log.push(
379 + Scheduler.unstable_yieldValue(
380 'BrokenComponentWillMountErrorBoundary static getDerivedStateFromError',
381 );
382 return {error};
@@ -305,28 +387,40 @@ describe('ReactErrorBoundaries', () => {
387 constructor(props) {
388 super(props);
389 this.state = {error: null};
308 - log.push('BrokenComponentDidMountErrorBoundary constructor');
390 + Scheduler.unstable_yieldValue(
391 + 'BrokenComponentDidMountErrorBoundary constructor',
392 + );
393 }
394 render() {
395 if (this.state.error) {
312 - log.push('BrokenComponentDidMountErrorBoundary render error');
396 + Scheduler.unstable_yieldValue(
397 + 'BrokenComponentDidMountErrorBoundary render error',
398 + );
399 return <div>Caught an error: {this.state.error.message}.</div>;
400 }
315 - log.push('BrokenComponentDidMountErrorBoundary render success');
401 + Scheduler.unstable_yieldValue(
402 + 'BrokenComponentDidMountErrorBoundary render success',
403 + );
404 return <div>{this.props.children}</div>;
405 }
406 UNSAFE_componentWillMount() {
319 - log.push('BrokenComponentDidMountErrorBoundary componentWillMount');
407 + Scheduler.unstable_yieldValue(
408 + 'BrokenComponentDidMountErrorBoundary componentWillMount',
409 + );
410 }
411 componentDidMount() {
322 - log.push('BrokenComponentDidMountErrorBoundary componentDidMount [!]');
412 + Scheduler.unstable_yieldValue(
413 + 'BrokenComponentDidMountErrorBoundary componentDidMount [!]',
414 + );
415 throw new Error('Hello');
416 }
417 componentWillUnmount() {
326 - log.push('BrokenComponentDidMountErrorBoundary componentWillUnmount');
418 + Scheduler.unstable_yieldValue(
419 + 'BrokenComponentDidMountErrorBoundary componentWillUnmount',
420 + );
421 }
422 static getDerivedStateFromError(error) {
329 - log.push(
423 + Scheduler.unstable_yieldValue(
424 'BrokenComponentDidMountErrorBoundary static getDerivedStateFromError',
425 );
426 return {error};
@@ -337,27 +431,39 @@ describe('ReactErrorBoundaries', () => {
431 constructor(props) {
432 super(props);
433 this.state = {error: null};
340 - log.push('BrokenRenderErrorBoundary constructor');
434 + Scheduler.unstable_yieldValue('BrokenRenderErrorBoundary constructor');
435 }
436 render() {
437 if (this.state.error) {
344 - log.push('BrokenRenderErrorBoundary render error [!]');
438 + Scheduler.unstable_yieldValue(
439 + 'BrokenRenderErrorBoundary render error [!]',
440 + );
441 throw new Error('Hello');
442 }
347 - log.push('BrokenRenderErrorBoundary render success');
443 + Scheduler.unstable_yieldValue(
444 + 'BrokenRenderErrorBoundary render success',
445 + );
446 return <div>{this.props.children}</div>;
447 }
448 UNSAFE_componentWillMount() {
351 - log.push('BrokenRenderErrorBoundary componentWillMount');
449 + Scheduler.unstable_yieldValue(
450 + 'BrokenRenderErrorBoundary componentWillMount',
451 + );
452 }
453 componentDidMount() {
354 - log.push('BrokenRenderErrorBoundary componentDidMount');
454 + Scheduler.unstable_yieldValue(
455 + 'BrokenRenderErrorBoundary componentDidMount',
456 + );
457 }
458 componentWillUnmount() {
357 - log.push('BrokenRenderErrorBoundary componentWillUnmount');
459 + Scheduler.unstable_yieldValue(
460 + 'BrokenRenderErrorBoundary componentWillUnmount',
461 + );
462 }
463 static getDerivedStateFromError(error) {
360 - log.push('BrokenRenderErrorBoundary static getDerivedStateFromError');
464 + Scheduler.unstable_yieldValue(
465 + 'BrokenRenderErrorBoundary static getDerivedStateFromError',
466 + );
467 return {error};
468 }
469 };
@@ -365,37 +471,37 @@ describe('ReactErrorBoundaries', () => {
471 BrokenRender = class extends React.Component {
472 constructor(props) {
473 super(props);
368 - log.push('BrokenRender constructor');
474 + Scheduler.unstable_yieldValue('BrokenRender constructor');
475 }
476 render() {
371 - log.push('BrokenRender render [!]');
477 + Scheduler.unstable_yieldValue('BrokenRender render [!]');
478 throw new Error('Hello');
479 }
480 UNSAFE_componentWillMount() {
375 - log.push('BrokenRender componentWillMount');
481 + Scheduler.unstable_yieldValue('BrokenRender componentWillMount');
482 }
483 componentDidMount() {
378 - log.push('BrokenRender componentDidMount');
484 + Scheduler.unstable_yieldValue('BrokenRender componentDidMount');
485 }
486 UNSAFE_componentWillReceiveProps() {
381 - log.push('BrokenRender componentWillReceiveProps');
487 + Scheduler.unstable_yieldValue('BrokenRender componentWillReceiveProps');
488 }
489 UNSAFE_componentWillUpdate() {
384 - log.push('BrokenRender componentWillUpdate');
490 + Scheduler.unstable_yieldValue('BrokenRender componentWillUpdate');
491 }
492 componentDidUpdate() {
387 - log.push('BrokenRender componentDidUpdate');
493 + Scheduler.unstable_yieldValue('BrokenRender componentDidUpdate');
494 }
495 componentWillUnmount() {
390 - log.push('BrokenRender componentWillUnmount');
496 + Scheduler.unstable_yieldValue('BrokenRender componentWillUnmount');
497 }
498 };
499
500 BrokenUseEffect = props => {
395 - log.push('BrokenUseEffect render');
501 + Scheduler.unstable_yieldValue('BrokenUseEffect render');
502
503 React.useEffect(() => {
398 - log.push('BrokenUseEffect useEffect [!]');
504 + Scheduler.unstable_yieldValue('BrokenUseEffect useEffect [!]');
505 throw new Error('Hello');
506 });
507
@@ -403,10 +509,12 @@ describe('ReactErrorBoundaries', () => {
509 };
510
511 BrokenUseLayoutEffect = props => {
406 - log.push('BrokenUseLayoutEffect render');
512 + Scheduler.unstable_yieldValue('BrokenUseLayoutEffect render');
513
514 React.useLayoutEffect(() => {
409 - log.push('BrokenUseLayoutEffect useLayoutEffect [!]');
515 + Scheduler.unstable_yieldValue(
516 + 'BrokenUseLayoutEffect useLayoutEffect [!]',
517 + );
518 throw new Error('Hello');
519 });
520
@@ -416,23 +524,25 @@ describe('ReactErrorBoundaries', () => {
524 NoopErrorBoundary = class extends React.Component {
525 constructor(props) {
526 super(props);
419 - log.push('NoopErrorBoundary constructor');
527 + Scheduler.unstable_yieldValue('NoopErrorBoundary constructor');
528 }
529 render() {
422 - log.push('NoopErrorBoundary render');
530 + Scheduler.unstable_yieldValue('NoopErrorBoundary render');
531 return <BrokenRender />;
532 }
533 UNSAFE_componentWillMount() {
426 - log.push('NoopErrorBoundary componentWillMount');
534 + Scheduler.unstable_yieldValue('NoopErrorBoundary componentWillMount');
535 }
536 componentDidMount() {
429 - log.push('NoopErrorBoundary componentDidMount');
537 + Scheduler.unstable_yieldValue('NoopErrorBoundary componentDidMount');
538 }
539 componentWillUnmount() {
432 - log.push('NoopErrorBoundary componentWillUnmount');
540 + Scheduler.unstable_yieldValue('NoopErrorBoundary componentWillUnmount');
541 }
542 static getDerivedStateFromError() {
435 - log.push('NoopErrorBoundary static getDerivedStateFromError');
543 + Scheduler.unstable_yieldValue(
544 + 'NoopErrorBoundary static getDerivedStateFromError',
545 + );
546 }
547 };
548
@@ -442,29 +552,41 @@ describe('ReactErrorBoundaries', () => {
552 };
553 constructor(props) {
554 super(props);
445 - log.push(`${this.props.logName} constructor`);
555 + Scheduler.unstable_yieldValue(`${this.props.logName} constructor`);
556 }
557 render() {
448 - log.push(`${this.props.logName} render`);
558 + Scheduler.unstable_yieldValue(`${this.props.logName} render`);
559 return <div>{this.props.children}</div>;
560 }
561 UNSAFE_componentWillMount() {
452 - log.push(`${this.props.logName} componentWillMount`);
562 + Scheduler.unstable_yieldValue(
563 + `${this.props.logName} componentWillMount`,
564 + );
565 }
566 componentDidMount() {
455 - log.push(`${this.props.logName} componentDidMount`);
567 + Scheduler.unstable_yieldValue(
568 + `${this.props.logName} componentDidMount`,
569 + );
570 }
571 UNSAFE_componentWillReceiveProps() {
458 - log.push(`${this.props.logName} componentWillReceiveProps`);
572 + Scheduler.unstable_yieldValue(
573 + `${this.props.logName} componentWillReceiveProps`,
574 + );
575 }
576 UNSAFE_componentWillUpdate() {
461 - log.push(`${this.props.logName} componentWillUpdate`);
577 + Scheduler.unstable_yieldValue(
578 + `${this.props.logName} componentWillUpdate`,
579 + );
580 }
581 componentDidUpdate() {
464 - log.push(`${this.props.logName} componentDidUpdate`);
582 + Scheduler.unstable_yieldValue(
583 + `${this.props.logName} componentDidUpdate`,
584 + );
585 }
586 componentWillUnmount() {
467 - log.push(`${this.props.logName} componentWillUnmount`);
587 + Scheduler.unstable_yieldValue(
588 + `${this.props.logName} componentWillUnmount`,
589 + );
590 }
591 };
592
@@ -472,37 +594,51 @@ describe('ReactErrorBoundaries', () => {
594 constructor(props) {
595 super(props);
596 this.state = {error: null};
475 - log.push(`${this.props.logName} constructor`);
597 + Scheduler.unstable_yieldValue(`${this.props.logName} constructor`);
598 }
599 render() {
600 if (this.state.error && !this.props.forceRetry) {
479 - log.push(`${this.props.logName} render error`);
601 + Scheduler.unstable_yieldValue(`${this.props.logName} render error`);
602 return this.props.renderError(this.state.error, this.props);
603 }
482 - log.push(`${this.props.logName} render success`);
604 + Scheduler.unstable_yieldValue(`${this.props.logName} render success`);
605 return <div>{this.props.children}</div>;
606 }
607 static getDerivedStateFromError(error) {
486 - log.push('ErrorBoundary static getDerivedStateFromError');
608 + Scheduler.unstable_yieldValue(
609 + 'ErrorBoundary static getDerivedStateFromError',
610 + );
611 return {error};
612 }
613 UNSAFE_componentWillMount() {
490 - log.push(`${this.props.logName} componentWillMount`);
614 + Scheduler.unstable_yieldValue(
615 + `${this.props.logName} componentWillMount`,
616 + );
617 }
618 componentDidMount() {
493 - log.push(`${this.props.logName} componentDidMount`);
619 + Scheduler.unstable_yieldValue(
620 + `${this.props.logName} componentDidMount`,
621 + );
622 }
623 UNSAFE_componentWillReceiveProps() {
496 - log.push(`${this.props.logName} componentWillReceiveProps`);
624 + Scheduler.unstable_yieldValue(
625 + `${this.props.logName} componentWillReceiveProps`,
626 + );
627 }
628 UNSAFE_componentWillUpdate() {
499 - log.push(`${this.props.logName} componentWillUpdate`);
629 + Scheduler.unstable_yieldValue(
630 + `${this.props.logName} componentWillUpdate`,
631 + );
632 }
633 componentDidUpdate() {
502 - log.push(`${this.props.logName} componentDidUpdate`);
634 + Scheduler.unstable_yieldValue(
635 + `${this.props.logName} componentDidUpdate`,
636 + );
637 }
638 componentWillUnmount() {
505 - log.push(`${this.props.logName} componentWillUnmount`);
639 + Scheduler.unstable_yieldValue(
640 + `${this.props.logName} componentWillUnmount`,
641 + );
642 }
643 };
644 ErrorBoundary.defaultProps = {
@@ -519,23 +655,27 @@ describe('ReactErrorBoundaries', () => {
655 RetryErrorBoundary = class extends React.Component {
656 constructor(props) {
657 super(props);
522 - log.push('RetryErrorBoundary constructor');
658 + Scheduler.unstable_yieldValue('RetryErrorBoundary constructor');
659 }
660 render() {
525 - log.push('RetryErrorBoundary render');
661 + Scheduler.unstable_yieldValue('RetryErrorBoundary render');
662 return <BrokenRender />;
663 }
664 UNSAFE_componentWillMount() {
529 - log.push('RetryErrorBoundary componentWillMount');
665 + Scheduler.unstable_yieldValue('RetryErrorBoundary componentWillMount');
666 }
667 componentDidMount() {
532 - log.push('RetryErrorBoundary componentDidMount');
668 + Scheduler.unstable_yieldValue('RetryErrorBoundary componentDidMount');
669 }
670 componentWillUnmount() {
535 - log.push('RetryErrorBoundary componentWillUnmount');
671 + Scheduler.unstable_yieldValue(
672 + 'RetryErrorBoundary componentWillUnmount',
673 + );
674 }
675 static getDerivedStateFromError(error) {
538 - log.push('RetryErrorBoundary static getDerivedStateFromError [!]');
676 + Scheduler.unstable_yieldValue(
677 + 'RetryErrorBoundary static getDerivedStateFromError [!]',
678 + );
679 // In Fiber, calling setState() (and failing) is treated as a rethrow.
680 return {};
681 }
@@ -544,19 +684,19 @@ describe('ReactErrorBoundaries', () => {
684 ErrorMessage = class extends React.Component {
685 constructor(props) {
686 super(props);
547 - log.push('ErrorMessage constructor');
687 + Scheduler.unstable_yieldValue('ErrorMessage constructor');
688 }
689 UNSAFE_componentWillMount() {
550 - log.push('ErrorMessage componentWillMount');
690 + Scheduler.unstable_yieldValue('ErrorMessage componentWillMount');
691 }
692 componentDidMount() {
553 - log.push('ErrorMessage componentDidMount');
693 + Scheduler.unstable_yieldValue('ErrorMessage componentDidMount');
694 }
695 componentWillUnmount() {
556 - log.push('ErrorMessage componentWillUnmount');
696 + Scheduler.unstable_yieldValue('ErrorMessage componentWillUnmount');
697 }
698 render() {
559 - log.push('ErrorMessage render');
699 + Scheduler.unstable_yieldValue('ErrorMessage render');
700 return <div>Caught an error: {this.props.message}.</div>;
701 }
702 };
@@ -658,7 +798,7 @@ describe('ReactErrorBoundaries', () => {
798 });
799
800 expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
661 - expect(log).toEqual([
801 + expect(Scheduler).toHaveYielded([
802 'ErrorBoundary constructor',
803 'ErrorBoundary componentWillMount',
804 'ErrorBoundary render success',
@@ -672,9 +812,8 @@ describe('ReactErrorBoundaries', () => {
812 'ErrorBoundary componentDidMount',
813 ]);
814
675 - log.length = 0;
815 ReactDOM.unmountComponentAtNode(container);
677 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
816 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
817 });
818
819 it('renders an error state if child throws in render', () => {
@@ -686,7 +825,7 @@ describe('ReactErrorBoundaries', () => {
825 container,
826 );
827 expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
689 - expect(log).toEqual([
828 + expect(Scheduler).toHaveYielded([
829 'ErrorBoundary constructor',
830 'ErrorBoundary componentWillMount',
831 'ErrorBoundary render success',
@@ -700,9 +839,8 @@ describe('ReactErrorBoundaries', () => {
839 'ErrorBoundary componentDidMount',
840 ]);
841
703 - log.length = 0;
842 ReactDOM.unmountComponentAtNode(container);
705 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
843 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
844 });
845
846 it('renders an error state if child throws in constructor', () => {
@@ -714,7 +852,7 @@ describe('ReactErrorBoundaries', () => {
852 container,
853 );
854 expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
717 - expect(log).toEqual([
855 + expect(Scheduler).toHaveYielded([
856 'ErrorBoundary constructor',
857 'ErrorBoundary componentWillMount',
858 'ErrorBoundary render success',
@@ -726,9 +864,8 @@ describe('ReactErrorBoundaries', () => {
864 'ErrorBoundary componentDidMount',
865 ]);
866
729 - log.length = 0;
867 ReactDOM.unmountComponentAtNode(container);
731 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
868 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
869 });
870
871 it('renders an error state if child throws in componentWillMount', () => {
@@ -740,7 +877,7 @@ describe('ReactErrorBoundaries', () => {
877 container,
878 );
879 expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
743 - expect(log).toEqual([
880 + expect(Scheduler).toHaveYielded([
881 'ErrorBoundary constructor',
882 'ErrorBoundary componentWillMount',
883 'ErrorBoundary render success',
@@ -753,9 +890,8 @@ describe('ReactErrorBoundaries', () => {
890 'ErrorBoundary componentDidMount',
891 ]);
892
756 - log.length = 0;
893 ReactDOM.unmountComponentAtNode(container);
758 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
894 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
895 });
896
897 it('renders an error state if context provider throws in componentWillMount', () => {
@@ -834,7 +970,7 @@ describe('ReactErrorBoundaries', () => {
970 </ErrorBoundary>,
971 container,
972 );
837 - expect(log).toEqual([
973 + expect(Scheduler).toHaveYielded([
974 'ErrorBoundary constructor',
975 'ErrorBoundary componentWillMount',
976 'ErrorBoundary render success',
@@ -851,9 +987,8 @@ describe('ReactErrorBoundaries', () => {
987 'ErrorBoundary componentDidMount',
988 ]);
989
854 - log.length = 0;
990 ReactDOM.unmountComponentAtNode(container);
856 - expect(log).toEqual([
991 + expect(Scheduler).toHaveYielded([
992 'ErrorBoundary componentWillUnmount',
993 'ErrorMessage componentWillUnmount',
994 ]);
@@ -870,7 +1005,7 @@ describe('ReactErrorBoundaries', () => {
1005 container,
1006 );
1007 expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
873 - expect(log).toEqual([
1008 + expect(Scheduler).toHaveYielded([
1009 'ErrorBoundary constructor',
1010 'ErrorBoundary componentWillMount',
1011 'ErrorBoundary render success',
@@ -894,9 +1029,8 @@ describe('ReactErrorBoundaries', () => {
1029 'ErrorBoundary componentDidMount',
1030 ]);
1031
897 - log.length = 0;
1032 ReactDOM.unmountComponentAtNode(container);
899 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
1033 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
1034 });
1035
1036 it('propagates errors inside boundary during componentWillMount', () => {
@@ -908,7 +1042,7 @@ describe('ReactErrorBoundaries', () => {
1042 container,
1043 );
1044 expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
911 - expect(log).toEqual([
1045 + expect(Scheduler).toHaveYielded([
1046 'ErrorBoundary constructor',
1047 'ErrorBoundary componentWillMount',
1048 'ErrorBoundary render success',
@@ -921,9 +1055,8 @@ describe('ReactErrorBoundaries', () => {
1055 'ErrorBoundary componentDidMount',
1056 ]);
1057
924 - log.length = 0;
1058 ReactDOM.unmountComponentAtNode(container);
926 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
1059 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
1060 });
1061
1062 it('propagates errors inside boundary while rendering error state', () => {
@@ -937,7 +1070,7 @@ describe('ReactErrorBoundaries', () => {
1070 container,
1071 );
1072 expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
940 - expect(log).toEqual([
1073 + expect(Scheduler).toHaveYielded([
1074 'ErrorBoundary constructor',
1075 'ErrorBoundary componentWillMount',
1076 'ErrorBoundary render success',
@@ -958,9 +1091,8 @@ describe('ReactErrorBoundaries', () => {
1091 'ErrorBoundary componentDidMount',
1092 ]);
1093
961 - log.length = 0;
1094 ReactDOM.unmountComponentAtNode(container);
963 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
1095 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
1096 });
1097
1098 it('does not call componentWillUnmount when aborting initial mount', () => {
@@ -974,7 +1106,7 @@ describe('ReactErrorBoundaries', () => {
1106 container,
1107 );
1108 expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
977 - expect(log).toEqual([
1109 + expect(Scheduler).toHaveYielded([
1110 'ErrorBoundary constructor',
1111 'ErrorBoundary componentWillMount',
1112 'ErrorBoundary render success',
@@ -997,17 +1129,16 @@ describe('ReactErrorBoundaries', () => {
1129 'ErrorBoundary componentDidMount',
1130 ]);
1131
1000 - log.length = 0;
1132 ReactDOM.unmountComponentAtNode(container);
1002 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
1133 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
1134 });
1135
1136 it('resets callback refs if mounting aborts', () => {
1137 function childRef(x) {
1007 - log.push('Child ref is set to ' + x);
1138 + Scheduler.unstable_yieldValue('Child ref is set to ' + x);
1139 }
1140 function errorMessageRef(x) {
1010 - log.push('Error message ref is set to ' + x);
1141 + Scheduler.unstable_yieldValue('Error message ref is set to ' + x);
1142 }
1143
1144 const container = document.createElement('div');
@@ -1019,7 +1150,7 @@ describe('ReactErrorBoundaries', () => {
1150 container,
1151 );
1152 expect(container.textContent).toBe('Caught an error: Hello.');
1022 - expect(log).toEqual([
1153 + expect(Scheduler).toHaveYielded([
1154 'ErrorBoundary constructor',
1155 'ErrorBoundary componentWillMount',
1156 'ErrorBoundary render success',
@@ -1034,9 +1165,8 @@ describe('ReactErrorBoundaries', () => {
1165 'ErrorBoundary componentDidMount',
1166 ]);
1167
1037 - log.length = 0;
1168 ReactDOM.unmountComponentAtNode(container);
1039 - expect(log).toEqual([
1169 + expect(Scheduler).toHaveYielded([
1170 'ErrorBoundary componentWillUnmount',
1171 'Error message ref is set to null',
1172 ]);
@@ -1055,7 +1185,7 @@ describe('ReactErrorBoundaries', () => {
1185 container,
1186 );
1187 expect(container.textContent).toBe('Caught an error: Hello.');
1058 - expect(log).toEqual([
1188 + expect(Scheduler).toHaveYielded([
1189 'ErrorBoundary constructor',
1190 'ErrorBoundary componentWillMount',
1191 'ErrorBoundary render success',
@@ -1072,9 +1202,8 @@ describe('ReactErrorBoundaries', () => {
1202 '[object HTMLDivElement]',
1203 );
1204
1075 - log.length = 0;
1205 ReactDOM.unmountComponentAtNode(container);
1077 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
1206 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
1207 expect(errorMessageRef.current).toEqual(null);
1208 });
1209
@@ -1087,16 +1216,15 @@ describe('ReactErrorBoundaries', () => {
1216 container,
1217 );
1218 expect(container.firstChild.textContent).toBe('Mounted successfully.');
1090 - expect(log).toEqual([
1219 + expect(Scheduler).toHaveYielded([
1220 'ErrorBoundary constructor',
1221 'ErrorBoundary componentWillMount',
1222 'ErrorBoundary render success',
1223 'ErrorBoundary componentDidMount',
1224 ]);
1225
1097 - log.length = 0;
1226 ReactDOM.unmountComponentAtNode(container);
1099 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
1227 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
1228 });
1229
1230 it('catches if child throws in constructor during update', () => {
@@ -1107,7 +1235,7 @@ describe('ReactErrorBoundaries', () => {
1235 </ErrorBoundary>,
1236 container,
1237 );
1110 - log.length = 0;
1238 + Scheduler.unstable_clearYields();
1239 ReactDOM.render(
1240 <ErrorBoundary>
1241 <Normal />
@@ -1117,7 +1245,7 @@ describe('ReactErrorBoundaries', () => {
1245 container,
1246 );
1247 expect(container.textContent).toBe('Caught an error: Hello.');
1120 - expect(log).toEqual([
1248 + expect(Scheduler).toHaveYielded([
1249 'ErrorBoundary componentWillReceiveProps',
1250 'ErrorBoundary componentWillUpdate',
1251 'ErrorBoundary render success',
@@ -1139,9 +1267,8 @@ describe('ReactErrorBoundaries', () => {
1267 'ErrorBoundary componentDidUpdate',
1268 ]);
1269
1142 - log.length = 0;
1270 ReactDOM.unmountComponentAtNode(container);
1144 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
1271 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
1272 });
1273
1274 it('catches if child throws in componentWillMount during update', () => {
@@ -1153,7 +1280,7 @@ describe('ReactErrorBoundaries', () => {
1280 container,
1281 );
1282
1156 - log.length = 0;
1283 + Scheduler.unstable_clearYields();
1284 ReactDOM.render(
1285 <ErrorBoundary>
1286 <Normal />
@@ -1163,7 +1290,7 @@ describe('ReactErrorBoundaries', () => {
1290 container,
1291 );
1292 expect(container.textContent).toBe('Caught an error: Hello.');
1166 - expect(log).toEqual([
1293 + expect(Scheduler).toHaveYielded([
1294 'ErrorBoundary componentWillReceiveProps',
1295 'ErrorBoundary componentWillUpdate',
1296 'ErrorBoundary render success',
@@ -1186,9 +1313,8 @@ describe('ReactErrorBoundaries', () => {
1313 'ErrorBoundary componentDidUpdate',
1314 ]);
1315
1189 - log.length = 0;
1316 ReactDOM.unmountComponentAtNode(container);
1191 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
1317 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
1318 });
1319
1320 it('catches if child throws in componentWillReceiveProps during update', () => {
@@ -1201,7 +1327,7 @@ describe('ReactErrorBoundaries', () => {
1327 container,
1328 );
1329
1204 - log.length = 0;
1330 + Scheduler.unstable_clearYields();
1331 ReactDOM.render(
1332 <ErrorBoundary>
1333 <Normal />
@@ -1210,7 +1336,7 @@ describe('ReactErrorBoundaries', () => {
1336 container,
1337 );
1338 expect(container.textContent).toBe('Caught an error: Hello.');
1213 - expect(log).toEqual([
1339 + expect(Scheduler).toHaveYielded([
1340 'ErrorBoundary componentWillReceiveProps',
1341 'ErrorBoundary componentWillUpdate',
1342 'ErrorBoundary render success',
@@ -1229,9 +1355,8 @@ describe('ReactErrorBoundaries', () => {
1355 'ErrorBoundary componentDidUpdate',
1356 ]);
1357
1232 - log.length = 0;
1358 ReactDOM.unmountComponentAtNode(container);
1234 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
1359 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
1360 });
1361
1362 it('catches if child throws in componentWillUpdate during update', () => {
@@ -1244,7 +1369,7 @@ describe('ReactErrorBoundaries', () => {
1369 container,
1370 );
1371
1247 - log.length = 0;
1372 + Scheduler.unstable_clearYields();
1373 ReactDOM.render(
1374 <ErrorBoundary>
1375 <Normal />
@@ -1253,7 +1378,7 @@ describe('ReactErrorBoundaries', () => {
1378 container,
1379 );
1380 expect(container.textContent).toBe('Caught an error: Hello.');
1256 - expect(log).toEqual([
1381 + expect(Scheduler).toHaveYielded([
1382 'ErrorBoundary componentWillReceiveProps',
1383 'ErrorBoundary componentWillUpdate',
1384 'ErrorBoundary render success',
@@ -1272,9 +1397,8 @@ describe('ReactErrorBoundaries', () => {
1397 'ErrorBoundary componentDidUpdate',
1398 ]);
1399
1275 - log.length = 0;
1400 ReactDOM.unmountComponentAtNode(container);
1277 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
1401 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
1402 });
1403
1404 it('catches if child throws in render during update', () => {
@@ -1286,7 +1410,7 @@ describe('ReactErrorBoundaries', () => {
1410 container,
1411 );
1412
1289 - log.length = 0;
1413 + Scheduler.unstable_clearYields();
1414 ReactDOM.render(
1415 <ErrorBoundary>
1416 <Normal />
@@ -1296,7 +1420,7 @@ describe('ReactErrorBoundaries', () => {
1420 container,
1421 );
1422 expect(container.textContent).toBe('Caught an error: Hello.');
1299 - expect(log).toEqual([
1423 + expect(Scheduler).toHaveYielded([
1424 'ErrorBoundary componentWillReceiveProps',
1425 'ErrorBoundary componentWillUpdate',
1426 'ErrorBoundary render success',
@@ -1319,20 +1443,19 @@ describe('ReactErrorBoundaries', () => {
1443 'ErrorBoundary componentDidUpdate',
1444 ]);
1445
1322 - log.length = 0;
1446 ReactDOM.unmountComponentAtNode(container);
1324 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
1447 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
1448 });
1449
1450 it('keeps refs up-to-date during updates', () => {
1451 function child1Ref(x) {
1329 - log.push('Child1 ref is set to ' + x);
1452 + Scheduler.unstable_yieldValue('Child1 ref is set to ' + x);
1453 }
1454 function child2Ref(x) {
1332 - log.push('Child2 ref is set to ' + x);
1455 + Scheduler.unstable_yieldValue('Child2 ref is set to ' + x);
1456 }
1457 function errorMessageRef(x) {
1335 - log.push('Error message ref is set to ' + x);
1458 + Scheduler.unstable_yieldValue('Error message ref is set to ' + x);
1459 }
1460
1461 const container = document.createElement('div');
@@ -1342,7 +1465,7 @@ describe('ReactErrorBoundaries', () => {
1465 </ErrorBoundary>,
1466 container,
1467 );
1345 - expect(log).toEqual([
1468 + expect(Scheduler).toHaveYielded([
1469 'ErrorBoundary constructor',
1470 'ErrorBoundary componentWillMount',
1471 'ErrorBoundary render success',
@@ -1350,7 +1473,6 @@ describe('ReactErrorBoundaries', () => {
1473 'ErrorBoundary componentDidMount',
1474 ]);
1475
1353 - log.length = 0;
1476 ReactDOM.render(
1477 <ErrorBoundary errorMessageRef={errorMessageRef}>
1478 <div ref={child1Ref} />
@@ -1360,7 +1482,7 @@ describe('ReactErrorBoundaries', () => {
1482 container,
1483 );
1484 expect(container.textContent).toBe('Caught an error: Hello.');
1363 - expect(log).toEqual([
1485 + expect(Scheduler).toHaveYielded([
1486 'ErrorBoundary componentWillReceiveProps',
1487 'ErrorBoundary componentWillUpdate',
1488 'ErrorBoundary render success',
@@ -1379,9 +1501,8 @@ describe('ReactErrorBoundaries', () => {
1501 'ErrorBoundary componentDidUpdate',
1502 ]);
1503
1382 - log.length = 0;
1504 ReactDOM.unmountComponentAtNode(container);
1384 - expect(log).toEqual([
1505 + expect(Scheduler).toHaveYielded([
1506 'ErrorBoundary componentWillUnmount',
1507 'Error message ref is set to null',
1508 ]);
@@ -1398,7 +1519,7 @@ describe('ReactErrorBoundaries', () => {
1519 container,
1520 );
1521
1401 - log.length = 0;
1522 + Scheduler.unstable_clearYields();
1523 ReactDOM.render(
1524 <ErrorBoundary>
1525 <BrokenComponentWillUnmount />
@@ -1406,7 +1527,7 @@ describe('ReactErrorBoundaries', () => {
1527 container,
1528 );
1529 expect(container.textContent).toBe('Caught an error: Hello.');
1409 - expect(log).toEqual([
1530 + expect(Scheduler).toHaveYielded([
1531 'ErrorBoundary componentWillReceiveProps',
1532 'ErrorBoundary componentWillUpdate',
1533 'ErrorBoundary render success',
@@ -1438,9 +1559,8 @@ describe('ReactErrorBoundaries', () => {
1559 'ErrorBoundary componentDidUpdate',
1560 ]);
1561
1441 - log.length = 0;
1562 ReactDOM.unmountComponentAtNode(container);
1443 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
1563 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
1564 });
1565
1566 it('recovers from nested componentWillUnmount errors on update', () => {
@@ -1455,7 +1575,7 @@ describe('ReactErrorBoundaries', () => {
1575 container,
1576 );
1577
1458 - log.length = 0;
1578 + Scheduler.unstable_clearYields();
1579 ReactDOM.render(
1580 <ErrorBoundary>
1581 <Normal>
@@ -1465,7 +1585,7 @@ describe('ReactErrorBoundaries', () => {
1585 container,
1586 );
1587 expect(container.textContent).toBe('Caught an error: Hello.');
1468 - expect(log).toEqual([
1588 + expect(Scheduler).toHaveYielded([
1589 'ErrorBoundary componentWillReceiveProps',
1590 'ErrorBoundary componentWillUpdate',
1591 'ErrorBoundary render success',
@@ -1498,9 +1618,8 @@ describe('ReactErrorBoundaries', () => {
1618 'ErrorBoundary componentDidUpdate',
1619 ]);
1620
1501 - log.length = 0;
1621 ReactDOM.unmountComponentAtNode(container);
1503 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
1622 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
1623 });
1624
1625 it('picks the right boundary when handling unmounting errors', () => {
@@ -1525,7 +1644,7 @@ describe('ReactErrorBoundaries', () => {
1644 container,
1645 );
1646
1528 - log.length = 0;
1647 + Scheduler.unstable_clearYields();
1648 ReactDOM.render(
1649 <ErrorBoundary
1650 logName="OuterErrorBoundary"
@@ -1538,7 +1657,7 @@ describe('ReactErrorBoundaries', () => {
1657 container,
1658 );
1659 expect(container.textContent).toBe('Caught an inner error: Hello.');
1541 - expect(log).toEqual([
1660 + expect(Scheduler).toHaveYielded([
1661 // Update outer boundary
1662 'OuterErrorBoundary componentWillReceiveProps',
1663 'OuterErrorBoundary componentWillUpdate',
@@ -1562,9 +1681,8 @@ describe('ReactErrorBoundaries', () => {
1681 'InnerErrorBoundary componentDidUpdate',
1682 ]);
1683
1565 - log.length = 0;
1684 ReactDOM.unmountComponentAtNode(container);
1567 - expect(log).toEqual([
1685 + expect(Scheduler).toHaveYielded([
1686 'OuterErrorBoundary componentWillUnmount',
1687 'InnerErrorBoundary componentWillUnmount',
1688 ]);
@@ -1589,7 +1707,7 @@ describe('ReactErrorBoundaries', () => {
1707 expect(container.textContent).toBe('Caught an error: Hello.');
1708
1709 // Force the success path:
1592 - log.length = 0;
1710 + Scheduler.unstable_clearYields();
1711 ReactDOM.render(
1712 <ErrorBoundary forceRetry={true}>
1713 <Normal />
@@ -1597,7 +1715,7 @@ describe('ReactErrorBoundaries', () => {
1715 container,
1716 );
1717 expect(container.textContent).not.toContain('Caught an error');
1600 - expect(log).toEqual([
1718 + expect(Scheduler).toHaveYielded([
1719 'ErrorBoundary componentWillReceiveProps',
1720 'ErrorBoundary componentWillUpdate',
1721 'ErrorBoundary render success',
@@ -1610,9 +1728,8 @@ describe('ReactErrorBoundaries', () => {
1728 'ErrorBoundary componentDidUpdate',
1729 ]);
1730
1613 - log.length = 0;
1731 ReactDOM.unmountComponentAtNode(container);
1615 - expect(log).toEqual([
1732 + expect(Scheduler).toHaveYielded([
1733 'ErrorBoundary componentWillUnmount',
1734 'Normal componentWillUnmount',
1735 ]);
@@ -1656,9 +1773,9 @@ describe('ReactErrorBoundaries', () => {
1773 ReactDOM.render(<ErrorBoundary />, container);
1774 expect(container.textContent).toBe('Caught an error: Hello.');
1775
1659 - log.length = 0;
1776 + Scheduler.unstable_clearYields();
1777 ReactDOM.unmountComponentAtNode(container);
1661 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
1778 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
1779 });
1780
1781 it("doesn't get into inconsistent state during additions", () => {
@@ -1674,9 +1791,9 @@ describe('ReactErrorBoundaries', () => {
1791 );
1792 expect(container.textContent).toBe('Caught an error: Hello.');
1793
1677 - log.length = 0;
1794 + Scheduler.unstable_clearYields();
1795 ReactDOM.unmountComponentAtNode(container);
1679 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
1796 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
1797 });
1798
1799 it("doesn't get into inconsistent state during reorders", () => {
@@ -1722,9 +1839,9 @@ describe('ReactErrorBoundaries', () => {
1839 );
1840 expect(container.textContent).toBe('Caught an error: Hello.');
1841
1725 - log.length = 0;
1842 + Scheduler.unstable_clearYields();
1843 ReactDOM.unmountComponentAtNode(container);
1727 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
1844 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
1845 });
1846
1847 it('catches errors originating downstream', () => {
@@ -1734,7 +1851,7 @@ describe('ReactErrorBoundaries', () => {
1851
1852 render() {
1853 if (fail) {
1737 - log.push('Stateful render [!]');
1854 + Scheduler.unstable_yieldValue('Stateful render [!]');
1855 throw new Error('Hello');
1856 }
1857 return <div>{this.props.children}</div>;
@@ -1750,13 +1867,13 @@ describe('ReactErrorBoundaries', () => {
1867 container,
1868 );
1869
1753 - log.length = 0;
1870 + Scheduler.unstable_clearYields();
1871 expect(() => {
1872 fail = true;
1873 statefulInst.forceUpdate();
1874 }).not.toThrow();
1875
1759 - expect(log).toEqual([
1876 + expect(Scheduler).toHaveYielded([
1877 'Stateful render [!]',
1878 'ErrorBoundary static getDerivedStateFromError',
1879 'ErrorBoundary componentWillUpdate',
@@ -1764,9 +1881,8 @@ describe('ReactErrorBoundaries', () => {
1881 'ErrorBoundary componentDidUpdate',
1882 ]);
1883
1767 - log.length = 0;
1884 ReactDOM.unmountComponentAtNode(container);
1769 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
1885 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
1886 });
1887
1888 it('catches errors in componentDidMount', () => {
@@ -1781,7 +1897,7 @@ describe('ReactErrorBoundaries', () => {
1897 </ErrorBoundary>,
1898 container,
1899 );
1784 - expect(log).toEqual([
1900 + expect(Scheduler).toHaveYielded([
1901 'ErrorBoundary constructor',
1902 'ErrorBoundary componentWillMount',
1903 'ErrorBoundary render success',
@@ -1823,9 +1939,8 @@ describe('ReactErrorBoundaries', () => {
1939 'ErrorBoundary componentDidUpdate',
1940 ]);
1941
1826 - log.length = 0;
1942 ReactDOM.unmountComponentAtNode(container);
1828 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
1943 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
1944 });
1945
1946 it('catches errors in componentDidUpdate', () => {
@@ -1837,14 +1952,14 @@ describe('ReactErrorBoundaries', () => {
1952 container,
1953 );
1954
1840 - log.length = 0;
1955 + Scheduler.unstable_clearYields();
1956 ReactDOM.render(
1957 <ErrorBoundary>
1958 <BrokenComponentDidUpdate />
1959 </ErrorBoundary>,
1960 container,
1961 );
1847 - expect(log).toEqual([
1962 + expect(Scheduler).toHaveYielded([
1963 'ErrorBoundary componentWillReceiveProps',
1964 'ErrorBoundary componentWillUpdate',
1965 'ErrorBoundary render success',
@@ -1862,9 +1977,8 @@ describe('ReactErrorBoundaries', () => {
1977 'ErrorBoundary componentDidUpdate',
1978 ]);
1979
1865 - log.length = 0;
1980 ReactDOM.unmountComponentAtNode(container);
1867 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
1981 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
1982 });
1983
1984 it('catches errors in useEffect', () => {
@@ -1876,7 +1990,7 @@ describe('ReactErrorBoundaries', () => {
1990 </ErrorBoundary>,
1991 container,
1992 );
1879 - expect(log).toEqual([
1993 + expect(Scheduler).toHaveYielded([
1994 'ErrorBoundary constructor',
1995 'ErrorBoundary componentWillMount',
1996 'ErrorBoundary render success',
@@ -1885,11 +1999,11 @@ describe('ReactErrorBoundaries', () => {
1999 ]);
2000
2001 expect(container.firstChild.textContent).toBe('Initial value');
1888 - log.length = 0;
2002 + Scheduler.unstable_clearYields();
2003 });
2004
2005 // verify flushed passive effects and handle the error
1892 - expect(log).toEqual([
2006 + expect(Scheduler).toHaveYielded([
2007 'BrokenUseEffect useEffect [!]',
2008 // Handle the error
2009 'ErrorBoundary static getDerivedStateFromError',
@@ -1909,7 +2023,7 @@ describe('ReactErrorBoundaries', () => {
2023 </ErrorBoundary>,
2024 container,
2025 );
1912 - expect(log).toEqual([
2026 + expect(Scheduler).toHaveYielded([
2027 'ErrorBoundary constructor',
2028 'ErrorBoundary componentWillMount',
2029 'ErrorBoundary render success',
@@ -1941,7 +2055,7 @@ describe('ReactErrorBoundaries', () => {
2055 container,
2056 );
2057 expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
1944 - expect(log).toEqual([
2058 + expect(Scheduler).toHaveYielded([
2059 'ErrorBoundary constructor',
2060 'ErrorBoundary componentWillMount',
2061 'ErrorBoundary render success',
@@ -1960,9 +2074,8 @@ describe('ReactErrorBoundaries', () => {
2074 'ErrorBoundary componentDidUpdate',
2075 ]);
2076
1963 - log.length = 0;
2077 ReactDOM.unmountComponentAtNode(container);
1965 - expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
2078 + expect(Scheduler).toHaveYielded(['ErrorBoundary componentWillUnmount']);
2079 });
2080
2081 it('calls static getDerivedStateFromError for each error that is captured', () => {
@@ -1992,7 +2105,7 @@ describe('ReactErrorBoundaries', () => {
2105 container,
2106 );
2107
1995 - log.length = 0;
2108 + Scheduler.unstable_clearYields();
2109 ReactDOM.render(
2110 <ErrorBoundary logName="OuterErrorBoundary">
2111 <ErrorBoundary
@@ -2012,7 +2125,7 @@ describe('ReactErrorBoundaries', () => {
2125 expect(container.firstChild.textContent).toBe(
2126 'Caught an unmounting error: E2.' + 'Caught an updating error: E4.',
2127 );
2015 - expect(log).toEqual([
2128 + expect(Scheduler).toHaveYielded([
2129 // Begin update phase
2130 'OuterErrorBoundary componentWillReceiveProps',
2131 'OuterErrorBoundary componentWillUpdate',
@@ -2057,9 +2170,8 @@ describe('ReactErrorBoundaries', () => {
2170 'InnerUpdateBoundary componentDidUpdate',
2171 ]);
2172
2060 - log.length = 0;
2173 ReactDOM.unmountComponentAtNode(container);
2062 - expect(log).toEqual([
2174 + expect(Scheduler).toHaveYielded([
2175 'OuterErrorBoundary componentWillUnmount',
2176 'InnerUnmountBoundary componentWillUnmount',
2177 'InnerUpdateBoundary componentWillUnmount',
@@ -2111,7 +2223,7 @@ describe('ReactErrorBoundaries', () => {
2223 ),
2224 ).toThrow('Hello');
2225 expect(container.innerHTML).toBe('');
2114 - expect(log).toEqual([
2226 + expect(Scheduler).toHaveYielded([
2227 'NoopErrorBoundary constructor',
2228 'NoopErrorBoundary componentWillMount',
2229 'NoopErrorBoundary render',