@@ -116,28 +116,37 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
116
116
. join ( '\n' ) } `
117
117
) ;
118
118
119
+ const type = methodName === 'log' ? 'log' : 'warning' ;
119
120
const message =
120
121
`Expected test not to call ${ chalk . bold (
121
122
`console.${ methodName } ()`
122
123
) } .\n\n` +
123
- ' If the warning is expected, test for it explicitly by:\n' +
124
+ ` If the ${ type } is expected, test for it explicitly by:\n` +
124
125
`1. Using the ${ chalk . bold ( '.' + expectedMatcher + '()' ) } ` +
125
126
`matcher, or...\n` +
126
127
`2. Mock it out using ${ chalk . bold (
127
128
'spyOnDev'
128
129
) } (console, '${ methodName } ') or ${ chalk . bold (
129
130
'spyOnProd'
130
- ) } (console, '${ methodName } '), and test that the warning occurs.`;
131
+ ) } (console, '${ methodName } '), and test that the ${ type } occurs.`;
131
132
132
133
throw new Error ( `${ message } \n\n${ messages . join ( '\n\n' ) } ` ) ;
133
134
}
134
135
} ;
135
136
136
137
const unexpectedErrorCallStacks = [ ] ;
137
138
const unexpectedWarnCallStacks = [ ] ;
139
+ const unexpectedLogCallStacks = [ ] ;
138
140
139
141
const errorMethod = patchConsoleMethod ( 'error' , unexpectedErrorCallStacks ) ;
140
142
const warnMethod = patchConsoleMethod ( 'warn' , unexpectedWarnCallStacks ) ;
143
+ let logMethod ;
144
+
145
+ // Only assert console.log isn't called in CI so you can debug tests in DEV.
146
+ // The matchers will still work in DEV, so you can assert locally.
147
+ if ( process . env . CI ) {
148
+ logMethod = patchConsoleMethod ( 'log' , unexpectedLogCallStacks ) ;
149
+ }
141
150
142
151
const flushAllUnexpectedConsoleCalls = ( ) => {
143
152
flushUnexpectedConsoleCalls (
@@ -152,13 +161,25 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
152
161
'toWarnDev' ,
153
162
unexpectedWarnCallStacks
154
163
) ;
164
+ if ( logMethod ) {
165
+ flushUnexpectedConsoleCalls (
166
+ logMethod ,
167
+ 'log' ,
168
+ 'toLogDev' ,
169
+ unexpectedLogCallStacks
170
+ ) ;
171
+ unexpectedLogCallStacks . length = 0 ;
172
+ }
155
173
unexpectedErrorCallStacks . length = 0 ;
156
174
unexpectedWarnCallStacks . length = 0 ;
157
175
} ;
158
176
159
177
const resetAllUnexpectedConsoleCalls = ( ) => {
160
178
unexpectedErrorCallStacks . length = 0 ;
161
179
unexpectedWarnCallStacks . length = 0 ;
180
+ if ( logMethod ) {
181
+ unexpectedLogCallStacks . length = 0 ;
182
+ }
162
183
} ;
163
184
164
185
beforeEach ( resetAllUnexpectedConsoleCalls ) ;
0 commit comments