@@ -114,7 +114,7 @@ describe('console', () => {
114
114
} ) ;
115
115
116
116
it ( 'should not append multiple stacks' , ( ) => {
117
- const Child = ( ) => {
117
+ const Child = ( { children } ) => {
118
118
fakeConsole . warn ( 'warn\n in Child (at fake.js:123)' ) ;
119
119
fakeConsole . error ( 'error' , '\n in Child (at fake.js:123)' ) ;
120
120
return null ;
@@ -135,12 +135,12 @@ describe('console', () => {
135
135
136
136
it ( 'should append component stacks to errors and warnings logged during render' , ( ) => {
137
137
const Intermediate = ( { children} ) => children ;
138
- const Parent = ( ) => (
138
+ const Parent = ( { children } ) => (
139
139
< Intermediate >
140
140
< Child />
141
141
</ Intermediate >
142
142
) ;
143
- const Child = ( ) => {
143
+ const Child = ( { children } ) => {
144
144
fakeConsole . error ( 'error' ) ;
145
145
fakeConsole . log ( 'log' ) ;
146
146
fakeConsole . warn ( 'warn' ) ;
@@ -149,42 +149,31 @@ describe('console', () => {
149
149
150
150
act ( ( ) => ReactDOM . render ( < Parent /> , document . createElement ( 'div' ) ) ) ;
151
151
152
- // TRICKY DevTools console override re-renders the component to intentionally trigger an error,
153
- // in which case all of the mock functions will be called an additional time.
154
-
155
- expect ( mockError ) . toHaveBeenCalledTimes ( 2 ) ;
156
- expect ( mockError . mock . calls [ 0 ] ) . toHaveLength ( 1 ) ;
157
- expect ( mockError . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'error' ) ;
158
- expect ( mockError . mock . calls [ 1 ] ) . toHaveLength ( 2 ) ;
159
- expect ( mockError . mock . calls [ 1 ] [ 0 ] ) . toBe ( 'error' ) ;
160
- expect ( normalizeCodeLocInfo ( mockError . mock . calls [ 1 ] [ 1 ] ) ) . toBe (
161
- '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
162
- ) ;
163
-
164
- expect ( mockLog ) . toHaveBeenCalledTimes ( 2 ) ;
152
+ expect ( mockLog ) . toHaveBeenCalledTimes ( 1 ) ;
165
153
expect ( mockLog . mock . calls [ 0 ] ) . toHaveLength ( 1 ) ;
166
154
expect ( mockLog . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'log' ) ;
167
- expect ( mockLog . mock . calls [ 1 ] ) . toHaveLength ( 1 ) ;
168
- expect ( mockLog . mock . calls [ 1 ] [ 0 ] ) . toBe ( 'log' ) ;
169
-
170
- expect ( mockWarn ) . toHaveBeenCalledTimes ( 2 ) ;
171
- expect ( mockWarn . mock . calls [ 0 ] ) . toHaveLength ( 1 ) ;
155
+ expect ( mockWarn ) . toHaveBeenCalledTimes ( 1 ) ;
156
+ expect ( mockWarn . mock . calls [ 0 ] ) . toHaveLength ( 2 ) ;
172
157
expect ( mockWarn . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'warn' ) ;
173
- expect ( mockWarn . mock . calls [ 1 ] ) . toHaveLength ( 2 ) ;
174
- expect ( mockWarn . mock . calls [ 1 ] [ 0 ] ) . toBe ( 'warn' ) ;
175
- expect ( normalizeCodeLocInfo ( mockWarn . mock . calls [ 1 ] [ 1 ] ) ) . toEqual (
158
+ expect ( normalizeCodeLocInfo ( mockWarn . mock . calls [ 0 ] [ 1 ] ) ) . toEqual (
159
+ '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
160
+ ) ;
161
+ expect ( mockError ) . toHaveBeenCalledTimes ( 1 ) ;
162
+ expect ( mockError . mock . calls [ 0 ] ) . toHaveLength ( 2 ) ;
163
+ expect ( mockError . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'error' ) ;
164
+ expect ( normalizeCodeLocInfo ( mockError . mock . calls [ 0 ] [ 1 ] ) ) . toBe (
176
165
'\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
177
166
) ;
178
167
} ) ;
179
168
180
169
it ( 'should append component stacks to errors and warnings logged from effects' , ( ) => {
181
170
const Intermediate = ( { children} ) => children ;
182
- const Parent = ( ) => (
171
+ const Parent = ( { children } ) => (
183
172
< Intermediate >
184
173
< Child />
185
174
</ Intermediate >
186
175
) ;
187
- const Child = ( ) => {
176
+ const Child = ( { children } ) => {
188
177
React . useLayoutEffect ( ( ) => {
189
178
fakeConsole . error ( 'active error' ) ;
190
179
fakeConsole . log ( 'active log' ) ;
@@ -231,7 +220,7 @@ describe('console', () => {
231
220
232
221
it ( 'should append component stacks to errors and warnings logged from commit hooks' , ( ) => {
233
222
const Intermediate = ( { children} ) => children ;
234
- const Parent = ( ) => (
223
+ const Parent = ( { children } ) => (
235
224
< Intermediate >
236
225
< Child />
237
226
</ Intermediate >
@@ -287,7 +276,7 @@ describe('console', () => {
287
276
288
277
it ( 'should append component stacks to errors and warnings logged from gDSFP' , ( ) => {
289
278
const Intermediate = ( { children} ) => children ;
290
- const Parent = ( ) => (
279
+ const Parent = ( { children } ) => (
291
280
< Intermediate >
292
281
< Child />
293
282
</ Intermediate >
@@ -325,7 +314,7 @@ describe('console', () => {
325
314
} ) ;
326
315
327
316
it ( 'should append stacks after being uninstalled and reinstalled' , ( ) => {
328
- const Child = ( ) => {
317
+ const Child = ( { children } ) => {
329
318
fakeConsole . warn ( 'warn' ) ;
330
319
fakeConsole . error ( 'error' ) ;
331
320
return null ;
@@ -344,20 +333,17 @@ describe('console', () => {
344
333
patchConsole ( ) ;
345
334
act ( ( ) => ReactDOM . render ( < Child /> , document . createElement ( 'div' ) ) ) ;
346
335
347
- // TRICKY DevTools console override re-renders the component to intentionally trigger an error,
348
- // in which case all of the mock functions will be called an additional time.
349
-
350
- expect ( mockWarn ) . toHaveBeenCalledTimes ( 3 ) ;
351
- expect ( mockWarn . mock . calls [ 2 ] ) . toHaveLength ( 2 ) ;
352
- expect ( mockWarn . mock . calls [ 2 ] [ 0 ] ) . toBe ( 'warn' ) ;
353
- expect ( normalizeCodeLocInfo ( mockWarn . mock . calls [ 2 ] [ 1 ] ) ) . toEqual (
336
+ expect ( mockWarn ) . toHaveBeenCalledTimes ( 2 ) ;
337
+ expect ( mockWarn . mock . calls [ 1 ] ) . toHaveLength ( 2 ) ;
338
+ expect ( mockWarn . mock . calls [ 1 ] [ 0 ] ) . toBe ( 'warn' ) ;
339
+ expect ( normalizeCodeLocInfo ( mockWarn . mock . calls [ 1 ] [ 1 ] ) ) . toEqual (
354
340
'\n in Child (at **)' ,
355
341
) ;
356
- expect ( mockError ) . toHaveBeenCalledTimes ( 3 ) ;
357
- expect ( mockError . mock . calls [ 2 ] ) . toHaveLength ( 2 ) ;
358
- expect ( mockError . mock . calls [ 2 ] [ 0 ] ) . toBe ( 'error' ) ;
359
- expect ( normalizeCodeLocInfo ( mockError . mock . calls [ 2 ] [ 1 ] ) ) . toBe (
342
+ expect ( mockError ) . toHaveBeenCalledTimes ( 2 ) ;
343
+ expect ( mockError . mock . calls [ 1 ] ) . toHaveLength ( 2 ) ;
344
+ expect ( mockError . mock . calls [ 1 ] [ 0 ] ) . toBe ( 'error' ) ;
345
+ expect ( normalizeCodeLocInfo ( mockError . mock . calls [ 1 ] [ 1 ] ) ) . toBe (
360
346
'\n in Child (at **)' ,
361
347
) ;
362
348
} ) ;
363
- } ) ;
349
+ } ) ;
0 commit comments