Skip to content

Commit 0d2bac7

Browse files
committed
Fix test
1 parent 511f9d8 commit 0d2bac7

File tree

3 files changed

+84
-41
lines changed

3 files changed

+84
-41
lines changed

packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,11 @@ describe('ReactHooksInspectionIntegration', () => {
898898

899899
await LazyFoo;
900900

901-
Scheduler.unstable_flushAll();
901+
expect(() => {
902+
Scheduler.unstable_flushAll();
903+
}).toErrorDev([
904+
'Foo: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead.',
905+
]);
902906

903907
const childFiber = renderer.root._currentFiber();
904908
const tree = ReactDebugTools.inspectHooksOfFiber(childFiber);

packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js

Lines changed: 68 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,18 @@ describe('ReactDOMFizzServer', () => {
291291
}
292292

293293
it('should asynchronously load a lazy component', async () => {
294+
const originalConsoleError = console.error;
295+
const mockError = jest.fn();
296+
console.error = (...args) => {
297+
if (args.length > 1) {
298+
if (typeof args[1] === 'object') {
299+
mockError(args[0].split('\n')[0]);
300+
return;
301+
}
302+
}
303+
mockError(...args.map(normalizeCodeLocInfo));
304+
};
305+
294306
let resolveA;
295307
const LazyA = React.lazy(() => {
296308
return new Promise(r => {
@@ -313,48 +325,66 @@ describe('ReactDOMFizzServer', () => {
313325
punctuation: '!',
314326
};
315327

316-
await act(async () => {
317-
const {pipe} = renderToPipeableStream(
318-
<div>
319-
<div>
320-
<Suspense fallback={<Text text="Loading..." />}>
321-
<LazyA text="Hello" />
322-
</Suspense>
323-
</div>
328+
try {
329+
await act(async () => {
330+
const {pipe} = renderToPipeableStream(
324331
<div>
325-
<Suspense fallback={<Text text="Loading..." />}>
326-
<LazyB text="world" />
327-
</Suspense>
328-
</div>
332+
<div>
333+
<Suspense fallback={<Text text="Loading..." />}>
334+
<LazyA text="Hello" />
335+
</Suspense>
336+
</div>
337+
<div>
338+
<Suspense fallback={<Text text="Loading..." />}>
339+
<LazyB text="world" />
340+
</Suspense>
341+
</div>
342+
</div>,
343+
);
344+
pipe(writable);
345+
});
346+
347+
expect(getVisibleChildren(container)).toEqual(
348+
<div>
349+
<div>Loading...</div>
350+
<div>Loading...</div>
351+
</div>,
352+
);
353+
await act(async () => {
354+
resolveA({default: Text});
355+
});
356+
expect(getVisibleChildren(container)).toEqual(
357+
<div>
358+
<div>Hello</div>
359+
<div>Loading...</div>
360+
</div>,
361+
);
362+
await act(async () => {
363+
resolveB({default: TextWithPunctuation});
364+
});
365+
expect(getVisibleChildren(container)).toEqual(
366+
<div>
367+
<div>Hello</div>
368+
<div>world!</div>
329369
</div>,
330370
);
331-
pipe(writable);
332-
});
333371

334-
expect(getVisibleChildren(container)).toEqual(
335-
<div>
336-
<div>Loading...</div>
337-
<div>Loading...</div>
338-
</div>,
339-
);
340-
await act(async () => {
341-
resolveA({default: Text});
342-
});
343-
expect(getVisibleChildren(container)).toEqual(
344-
<div>
345-
<div>Hello</div>
346-
<div>Loading...</div>
347-
</div>,
348-
);
349-
await act(async () => {
350-
resolveB({default: TextWithPunctuation});
351-
});
352-
expect(getVisibleChildren(container)).toEqual(
353-
<div>
354-
<div>Hello</div>
355-
<div>world!</div>
356-
</div>,
357-
);
372+
if (__DEV__) {
373+
expect(mockError).toHaveBeenCalledWith(
374+
'Warning: %s: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead.%s',
375+
'TextWithPunctuation',
376+
'\n in TextWithPunctuation (at **)\n' +
377+
' in Lazy (at **)\n' +
378+
' in Suspense (at **)\n' +
379+
' in div (at **)\n' +
380+
' in div (at **)',
381+
);
382+
} else {
383+
expect(mockError).not.toHaveBeenCalled();
384+
}
385+
} finally {
386+
console.error = originalConsoleError;
387+
}
358388
});
359389

360390
it('#23331: does not warn about hydration mismatches if something suspended in an earlier sibling', async () => {

packages/react-reconciler/src/__tests__/ReactMemo-test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ describe('memo', () => {
7575
}
7676
ReactNoop.render(<Outer />);
7777
expect(() => expect(Scheduler).toFlushWithoutYielding()).toErrorDev([
78+
'App: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead.',
7879
'Warning: Function components cannot be given refs. Attempts to access ' +
7980
'this ref will fail.',
8081
]);
@@ -441,7 +442,11 @@ describe('memo', () => {
441442
);
442443
expect(Scheduler).toFlushAndYield(['Loading...']);
443444
await Promise.resolve();
444-
expect(Scheduler).toFlushAndYield([15]);
445+
expect(() => {
446+
expect(Scheduler).toFlushAndYield([15]);
447+
}).toErrorDev([
448+
'Counter: Support for defaultProps will be removed from memo components in a future major release. Use JavaScript default parameters instead.',
449+
]);
445450
expect(ReactNoop.getChildren()).toEqual([span(15)]);
446451

447452
// Should bail out because props have not changed
@@ -552,7 +557,11 @@ describe('memo', () => {
552557
<Outer />
553558
</div>,
554559
);
555-
expect(Scheduler).toFlushWithoutYielding();
560+
expect(() => {
561+
expect(Scheduler).toFlushWithoutYielding();
562+
}).toErrorDev([
563+
'Inner: Support for defaultProps will be removed from memo components in a future major release. Use JavaScript default parameters instead.',
564+
]);
556565

557566
// Mount
558567
expect(() => {

0 commit comments

Comments
 (0)