1313const React = require ( 'react' ) ;
1414const stripAnsi = require ( 'strip-ansi' ) ;
1515const { startTransition, useDeferredValue} = React ;
16- const chalk = require ( 'chalk' ) ;
1716const ReactNoop = require ( 'react-noop-renderer' ) ;
1817const {
1918 waitFor,
@@ -25,7 +24,7 @@ const {
2524const act = require ( 'internal-test-utils' ) . act ;
2625const Scheduler = require ( 'scheduler/unstable_mock' ) ;
2726const {
28- flushAllUnexpectedConsoleCalls ,
27+ assertConsoleLogsCleared ,
2928 resetAllUnexpectedConsoleCalls,
3029 patchConsoleMethods,
3130} = require ( '../consoleMock' ) ;
@@ -205,16 +204,17 @@ describe('ReactInternalTestUtils console mocks', () => {
205204 it ( 'should fail if not asserted' , ( ) => {
206205 expect ( ( ) => {
207206 console . log ( 'hit' ) ;
208- flushAllUnexpectedConsoleCalls ( ) ;
209- } ) . toThrow ( `Expected test not to call ${ chalk . bold ( 'console.log()' ) } . ` ) ;
207+ assertConsoleLogsCleared ( ) ;
208+ } ) . toThrow ( `console.log was called without assertConsoleLogDev ` ) ;
210209 } ) ;
211210
212- // @gate __DEV__
213211 it ( 'should not fail if mocked with spyOnDev' , ( ) => {
214212 spyOnDev ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
215213 expect ( ( ) => {
216- console . log ( 'hit' ) ;
217- flushAllUnexpectedConsoleCalls ( ) ;
214+ if ( __DEV__ ) {
215+ console . log ( 'hit' ) ;
216+ }
217+ assertConsoleLogsCleared ( ) ;
218218 } ) . not . toThrow ( ) ;
219219 } ) ;
220220
@@ -223,41 +223,34 @@ describe('ReactInternalTestUtils console mocks', () => {
223223 spyOnProd ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
224224 expect ( ( ) => {
225225 console . log ( 'hit' ) ;
226- flushAllUnexpectedConsoleCalls ( ) ;
226+ assertConsoleLogsCleared ( ) ;
227227 } ) . not . toThrow ( ) ;
228228 } ) ;
229229
230230 it ( 'should not fail if mocked with spyOnDevAndProd' , ( ) => {
231231 spyOnDevAndProd ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
232232 expect ( ( ) => {
233233 console . log ( 'hit' ) ;
234- flushAllUnexpectedConsoleCalls ( ) ;
234+ assertConsoleLogsCleared ( ) ;
235235 } ) . not . toThrow ( ) ;
236236 } ) ;
237-
238- // @gate __DEV__
239- it ( 'should not fail with toLogDev' , ( ) => {
240- expect ( ( ) => {
241- console . log ( 'hit' ) ;
242- flushAllUnexpectedConsoleCalls ( ) ;
243- } ) . toLogDev ( [ 'hit' ] ) ;
244- } ) ;
245237 } ) ;
246238
247239 describe ( 'console.warn' , ( ) => {
248240 it ( 'should fail if not asserted' , ( ) => {
249241 expect ( ( ) => {
250242 console . warn ( 'hit' ) ;
251- flushAllUnexpectedConsoleCalls ( ) ;
252- } ) . toThrow ( `Expected test not to call ${ chalk . bold ( 'console.warn()' ) } .` ) ;
243+ assertConsoleLogsCleared ( ) ;
244+ } ) . toThrow ( 'console.warn was called without assertConsoleWarnDev' ) ;
253245 } ) ;
254246
255- // @gate __DEV__
256247 it ( 'should not fail if mocked with spyOnDev' , ( ) => {
257248 spyOnDev ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
258249 expect ( ( ) => {
259- console . warn ( 'hit' ) ;
260- flushAllUnexpectedConsoleCalls ( ) ;
250+ if ( __DEV__ ) {
251+ console . warn ( 'hit' ) ;
252+ }
253+ assertConsoleLogsCleared ( ) ;
261254 } ) . not . toThrow ( ) ;
262255 } ) ;
263256
@@ -266,41 +259,34 @@ describe('ReactInternalTestUtils console mocks', () => {
266259 spyOnProd ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
267260 expect ( ( ) => {
268261 console . warn ( 'hit' ) ;
269- flushAllUnexpectedConsoleCalls ( ) ;
262+ assertConsoleLogsCleared ( ) ;
270263 } ) . not . toThrow ( ) ;
271264 } ) ;
272265
273266 it ( 'should not fail if mocked with spyOnDevAndProd' , ( ) => {
274267 spyOnDevAndProd ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
275268 expect ( ( ) => {
276269 console . warn ( 'hit' ) ;
277- flushAllUnexpectedConsoleCalls ( ) ;
270+ assertConsoleLogsCleared ( ) ;
278271 } ) . not . toThrow ( ) ;
279272 } ) ;
280-
281- // @gate __DEV__
282- it ( 'should not fail with toWarnDev' , ( ) => {
283- expect ( ( ) => {
284- console . warn ( 'hit' ) ;
285- flushAllUnexpectedConsoleCalls ( ) ;
286- } ) . toWarnDev ( [ 'hit' ] , { withoutStack : true } ) ;
287- } ) ;
288273 } ) ;
289274
290275 describe ( 'console.error' , ( ) => {
291276 it ( 'should fail if console.error is not asserted' , ( ) => {
292277 expect ( ( ) => {
293278 console . error ( 'hit' ) ;
294- flushAllUnexpectedConsoleCalls ( ) ;
295- } ) . toThrow ( `Expected test not to call ${ chalk . bold ( 'console.error()' ) } .` ) ;
279+ assertConsoleLogsCleared ( ) ;
280+ } ) . toThrow ( 'console.error was called without assertConsoleErrorDev' ) ;
296281 } ) ;
297282
298- // @gate __DEV__
299283 it ( 'should not fail if mocked with spyOnDev' , ( ) => {
300284 spyOnDev ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
301285 expect ( ( ) => {
302- console . error ( 'hit' ) ;
303- flushAllUnexpectedConsoleCalls ( ) ;
286+ if ( __DEV__ ) {
287+ console . error ( 'hit' ) ;
288+ }
289+ assertConsoleLogsCleared ( ) ;
304290 } ) . not . toThrow ( ) ;
305291 } ) ;
306292
@@ -309,25 +295,17 @@ describe('ReactInternalTestUtils console mocks', () => {
309295 spyOnProd ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
310296 expect ( ( ) => {
311297 console . error ( 'hit' ) ;
312- flushAllUnexpectedConsoleCalls ( ) ;
298+ assertConsoleLogsCleared ( ) ;
313299 } ) . not . toThrow ( ) ;
314300 } ) ;
315301
316302 it ( 'should not fail if mocked with spyOnDevAndProd' , ( ) => {
317303 spyOnDevAndProd ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
318304 expect ( ( ) => {
319305 console . error ( 'hit' ) ;
320- flushAllUnexpectedConsoleCalls ( ) ;
306+ assertConsoleLogsCleared ( ) ;
321307 } ) . not . toThrow ( ) ;
322308 } ) ;
323-
324- // @gate __DEV__
325- it ( 'should not fail with toErrorDev' , ( ) => {
326- expect ( ( ) => {
327- console . error ( 'hit' ) ;
328- flushAllUnexpectedConsoleCalls ( ) ;
329- } ) . toErrorDev ( [ 'hit' ] , { withoutStack : true } ) ;
330- } ) ;
331309 } ) ;
332310} ) ;
333311
@@ -361,17 +339,19 @@ describe('ReactInternalTestUtils console assertions', () => {
361339 } ) ;
362340
363341 describe ( 'assertConsoleLogDev' , ( ) => {
364- // @gate __DEV__
365342 it ( 'passes for a single log' , ( ) => {
366- console . log ( 'Hello' ) ;
343+ if ( __DEV__ ) {
344+ console . log ( 'Hello' ) ;
345+ }
367346 assertConsoleLogDev ( [ 'Hello' ] ) ;
368347 } ) ;
369348
370- // @gate __DEV__
371349 it ( 'passes for multiple logs' , ( ) => {
372- console . log ( 'Hello' ) ;
373- console . log ( 'Good day' ) ;
374- console . log ( 'Bye' ) ;
350+ if ( __DEV__ ) {
351+ console . log ( 'Hello' ) ;
352+ console . log ( 'Good day' ) ;
353+ console . log ( 'Bye' ) ;
354+ }
375355 assertConsoleLogDev ( [ 'Hello' , 'Good day' , 'Bye' ] ) ;
376356 } ) ;
377357
@@ -906,17 +886,19 @@ describe('ReactInternalTestUtils console assertions', () => {
906886 } ) ;
907887
908888 describe ( 'assertConsoleWarnDev' , ( ) => {
909- // @gate __DEV__
910889 it ( 'passes if an warning contains a stack' , ( ) => {
911- console . warn ( 'Hello\n in div' ) ;
890+ if ( __DEV__ ) {
891+ console . warn ( 'Hello\n in div' ) ;
892+ }
912893 assertConsoleWarnDev ( [ 'Hello' ] ) ;
913894 } ) ;
914895
915- // @gate __DEV__
916896 it ( 'passes if all warnings contain a stack' , ( ) => {
917- console . warn ( 'Hello\n in div' ) ;
918- console . warn ( 'Good day\n in div' ) ;
919- console . warn ( 'Bye\n in div' ) ;
897+ if ( __DEV__ ) {
898+ console . warn ( 'Hello\n in div' ) ;
899+ console . warn ( 'Good day\n in div' ) ;
900+ console . warn ( 'Bye\n in div' ) ;
901+ }
920902 assertConsoleWarnDev ( [ 'Hello' , 'Good day' , 'Bye' ] ) ;
921903 } ) ;
922904
@@ -1353,14 +1335,17 @@ describe('ReactInternalTestUtils console assertions', () => {
13531335 } ) ;
13541336
13551337 describe ( 'global withoutStack' , ( ) => {
1356- // @gate __DEV__
13571338 it ( 'passes if warnings without stack explicitly opt out' , ( ) => {
1358- console . warn ( 'Hello' ) ;
1339+ if ( __DEV__ ) {
1340+ console . warn ( 'Hello' ) ;
1341+ }
13591342 assertConsoleWarnDev ( [ 'Hello' ] , { withoutStack : true } ) ;
13601343
1361- console . warn ( 'Hello' ) ;
1362- console . warn ( 'Good day' ) ;
1363- console . warn ( 'Bye' ) ;
1344+ if ( __DEV__ ) {
1345+ console . warn ( 'Hello' ) ;
1346+ console . warn ( 'Good day' ) ;
1347+ console . warn ( 'Bye' ) ;
1348+ }
13641349
13651350 assertConsoleWarnDev ( [ 'Hello' , 'Good day' , 'Bye' ] , {
13661351 withoutStack : true ,
@@ -1460,11 +1445,12 @@ describe('ReactInternalTestUtils console assertions', () => {
14601445 } ) ;
14611446 } ) ;
14621447 describe ( 'local withoutStack' , ( ) => {
1463- // @gate __DEV__
14641448 it ( 'passes when expected withoutStack logs matches the actual logs' , ( ) => {
1465- console . warn ( 'Hello\n in div' ) ;
1466- console . warn ( 'Good day' ) ;
1467- console . warn ( 'Bye\n in div' ) ;
1449+ if ( __DEV__ ) {
1450+ console . warn ( 'Hello\n in div' ) ;
1451+ console . warn ( 'Good day' ) ;
1452+ console . warn ( 'Bye\n in div' ) ;
1453+ }
14681454 assertConsoleWarnDev ( [
14691455 'Hello' ,
14701456 [ 'Good day' , { withoutStack : true } ] ,
@@ -1981,17 +1967,19 @@ describe('ReactInternalTestUtils console assertions', () => {
19811967 } ) ;
19821968
19831969 describe ( 'assertConsoleErrorDev' , ( ) => {
1984- // @gate __DEV__
19851970 it ( 'passes if an error contains a stack' , ( ) => {
1986- console . error ( 'Hello\n in div' ) ;
1971+ if ( __DEV__ ) {
1972+ console . error ( 'Hello\n in div' ) ;
1973+ }
19871974 assertConsoleErrorDev ( [ 'Hello' ] ) ;
19881975 } ) ;
19891976
1990- // @gate __DEV__
19911977 it ( 'passes if all errors contain a stack' , ( ) => {
1992- console . error ( 'Hello\n in div' ) ;
1993- console . error ( 'Good day\n in div' ) ;
1994- console . error ( 'Bye\n in div' ) ;
1978+ if ( __DEV__ ) {
1979+ console . error ( 'Hello\n in div' ) ;
1980+ console . error ( 'Good day\n in div' ) ;
1981+ console . error ( 'Bye\n in div' ) ;
1982+ }
19951983 assertConsoleErrorDev ( [ 'Hello' , 'Good day' , 'Bye' ] ) ;
19961984 } ) ;
19971985
@@ -2446,14 +2434,17 @@ describe('ReactInternalTestUtils console assertions', () => {
24462434 } ) ;
24472435
24482436 describe ( 'global withoutStack' , ( ) => {
2449- // @gate __DEV__
24502437 it ( 'passes if errors without stack explicitly opt out' , ( ) => {
2451- console . error ( 'Hello' ) ;
2438+ if ( __DEV__ ) {
2439+ console . error ( 'Hello' ) ;
2440+ }
24522441 assertConsoleErrorDev ( [ 'Hello' ] , { withoutStack : true } ) ;
24532442
2454- console . error ( 'Hello' ) ;
2455- console . error ( 'Good day' ) ;
2456- console . error ( 'Bye' ) ;
2443+ if ( __DEV__ ) {
2444+ console . error ( 'Hello' ) ;
2445+ console . error ( 'Good day' ) ;
2446+ console . error ( 'Bye' ) ;
2447+ }
24572448
24582449 assertConsoleErrorDev ( [ 'Hello' , 'Good day' , 'Bye' ] , {
24592450 withoutStack : true ,
@@ -2553,11 +2544,12 @@ describe('ReactInternalTestUtils console assertions', () => {
25532544 } ) ;
25542545 } ) ;
25552546 describe ( 'local withoutStack' , ( ) => {
2556- // @gate __DEV__
25572547 it ( 'passes when expected withoutStack logs matches the actual logs' , ( ) => {
2558- console . error ( 'Hello\n in div' ) ;
2559- console . error ( 'Good day' ) ;
2560- console . error ( 'Bye\n in div' ) ;
2548+ if ( __DEV__ ) {
2549+ console . error ( 'Hello\n in div' ) ;
2550+ console . error ( 'Good day' ) ;
2551+ console . error ( 'Bye\n in div' ) ;
2552+ }
25612553 assertConsoleErrorDev ( [
25622554 'Hello' ,
25632555 [ 'Good day' , { withoutStack : true } ] ,
0 commit comments