@@ -2,7 +2,7 @@ import React from 'react';
22import { render , screen } from '@testing-library/react' ;
33import userEvent from '@testing-library/user-event' ;
44
5- import TestUtils from './TestUtils' ;
5+ import TestUtils , { ConsoleMethodName } from './TestUtils' ;
66import createMockProxy from './MockProxy' ;
77
88beforeEach ( ( ) => {
@@ -19,6 +19,42 @@ describe('asMock', () => {
1919 expect ( someFunc ( 'a,b,c' ) ) . toEqual ( 3 ) ;
2020} ) ;
2121
22+ /* eslint-disable no-console */
23+ describe ( 'disableConsoleOutput' , ( ) => {
24+ const arg0 = 'mock arg' ;
25+ const allMethodNames = Object . getOwnPropertyNames ( console ) . filter (
26+ ( name ) : name is ConsoleMethodName =>
27+ typeof console [ name as keyof Console ] === 'function'
28+ ) ;
29+
30+ it ( 'should disable all methods if given no method names' , ( ) => {
31+ TestUtils . disableConsoleOutput ( ) ;
32+
33+ allMethodNames . forEach ( methodName => {
34+ console [ methodName ] ( ) ;
35+
36+ expect ( console [ methodName ] ) . toHaveBeenCalled ( ) ;
37+ } ) ;
38+ } ) ;
39+
40+ it . each ( [
41+ [ [ 'log' ] ] ,
42+ [ [ 'warn' ] ] ,
43+ [ [ 'error' ] ] ,
44+ [ [ 'info' ] ] ,
45+ [ [ 'debug' ] ] ,
46+ [ allMethodNames ] ,
47+ ] as const ) ( 'should mock console method implementations: %s' , methodNames => {
48+ TestUtils . disableConsoleOutput ( ...methodNames ) ;
49+
50+ methodNames . forEach ( methodName => {
51+ console [ methodName ] ( arg0 ) ;
52+ expect ( console [ methodName ] ) . toHaveBeenCalledWith ( arg0 ) ;
53+ } ) ;
54+ } ) ;
55+ } ) ;
56+ /* eslint-enable no-console */
57+
2258describe ( 'findLastCall' , ( ) => {
2359 it ( 'should return undefined if call not matched' , ( ) => {
2460 const fn = jest . fn < void , [ string , number ] > ( ) ;
0 commit comments