@@ -20,7 +20,7 @@ let useState;
20
20
let useEffect ;
21
21
let useLayoutEffect ;
22
22
let assertLog ;
23
- let originalError ;
23
+ let assertConsoleErrorDev ;
24
24
25
25
// This tests shared behavior between the built-in and shim implementations of
26
26
// of useSyncExternalStore.
@@ -50,9 +50,6 @@ describe('Shared useSyncExternalStore behavior (shim and built-in)', () => {
50
50
: 'react-dom-17/umd/react-dom.production.min.js' ,
51
51
) ,
52
52
) ;
53
- // Because React 17 prints extra logs we need to ignore them.
54
- originalError = console . error ;
55
- console . error = jest . fn ( ) ;
56
53
}
57
54
React = require ( 'react' ) ;
58
55
ReactDOM = require ( 'react-dom' ) ;
@@ -63,6 +60,7 @@ describe('Shared useSyncExternalStore behavior (shim and built-in)', () => {
63
60
useLayoutEffect = React . useLayoutEffect ;
64
61
const InternalTestUtils = require ( 'internal-test-utils' ) ;
65
62
assertLog = InternalTestUtils . assertLog ;
63
+ assertConsoleErrorDev = InternalTestUtils . assertConsoleErrorDev ;
66
64
const internalAct = require ( 'internal-test-utils' ) . act ;
67
65
68
66
// The internal act implementation doesn't batch updates by default, since
@@ -85,11 +83,6 @@ describe('Shared useSyncExternalStore behavior (shim and built-in)', () => {
85
83
useSyncExternalStoreWithSelector =
86
84
require ( 'use-sync-external-store/shim/with-selector' ) . useSyncExternalStoreWithSelector ;
87
85
} ) ;
88
- afterEach ( ( ) => {
89
- if ( gate ( flags => flags . enableUseSyncExternalStoreShim ) ) {
90
- console . error = originalError ;
91
- }
92
- } ) ;
93
86
function Text ( { text} ) {
94
87
Scheduler . log ( text ) ;
95
88
return text ;
@@ -630,36 +623,30 @@ describe('Shared useSyncExternalStore behavior (shim and built-in)', () => {
630
623
const container = document . createElement ( 'div' ) ;
631
624
const root = createRoot ( container ) ;
632
625
await expect ( async ( ) => {
633
- await expect ( async ( ) => {
634
- await act ( ( ) => {
635
- ReactDOM . flushSync ( async ( ) =>
636
- root . render ( React . createElement ( App , null ) ) ,
637
- ) ;
638
- } ) ;
639
- } ) . rejects . toThrow (
640
- 'Maximum update depth exceeded. This can happen when a component repeatedly ' +
641
- 'calls setState inside componentWillUpdate or componentDidUpdate. React limits ' +
642
- 'the number of nested updates to prevent infinite loops.' ,
643
- ) ;
644
- } ) . toErrorDev (
626
+ await act ( ( ) => {
627
+ ReactDOM . flushSync ( async ( ) =>
628
+ root . render ( React . createElement ( App , null ) ) ,
629
+ ) ;
630
+ } ) ;
631
+ } ) . rejects . toThrow (
632
+ 'Maximum update depth exceeded. This can happen when a component repeatedly ' +
633
+ 'calls setState inside componentWillUpdate or componentDidUpdate. React limits ' +
634
+ 'the number of nested updates to prevent infinite loops.' ,
635
+ ) ;
636
+
637
+ assertConsoleErrorDev (
645
638
gate ( flags => flags . enableUseSyncExternalStoreShim )
646
639
? [
647
- 'Maximum update depth exceeded. ' ,
648
- 'The result of getSnapshot should be cached to avoid an infinite loop' ,
649
- 'The above error occurred in the' ,
640
+ [
641
+ 'The result of getSnapshot should be cached to avoid an infinite loop' ,
642
+ { withoutStack : true } ,
643
+ ] ,
644
+ 'Error: Maximum update depth exceeded' ,
645
+ 'The above error occurred i' ,
650
646
]
651
647
: [
652
648
'The result of getSnapshot should be cached to avoid an infinite loop' ,
653
649
] ,
654
- {
655
- withoutStack : gate ( flags => {
656
- if ( flags . enableUseSyncExternalStoreShim ) {
657
- // Stacks don't work when mixing the source and the npm package.
658
- return flags . source ? 1 : 0 ;
659
- }
660
- return false ;
661
- } ) ,
662
- } ,
663
650
) ;
664
651
} ) ;
665
652
it ( 'getSnapshot can return NaN without infinite loop warning' , async ( ) => {
@@ -850,10 +837,9 @@ describe('Shared useSyncExternalStore behavior (shim and built-in)', () => {
850
837
// client. To avoid this server mismatch warning, user must account for
851
838
// this themselves and return the correct value inside `getSnapshot`.
852
839
await act ( ( ) => {
853
- expect ( ( ) =>
854
- ReactDOM . hydrate ( React . createElement ( App , null ) , container ) ,
855
- ) . toErrorDev ( 'Text content did not match' ) ;
840
+ ReactDOM . hydrate ( React . createElement ( App , null ) , container ) ;
856
841
} ) ;
842
+ assertConsoleErrorDev ( [ 'Text content did not match' ] ) ;
857
843
assertLog ( [ 'client' , 'Passive effect: client' ] ) ;
858
844
}
859
845
expect ( container . textContent ) . toEqual ( 'client' ) ;
0 commit comments