@@ -12,6 +12,7 @@ route: '/reference/api'
12
12
- [ ` cleanup ` ] ( /reference/api#cleanup )
13
13
- [ ` addCleanup ` ] ( /reference/api#addcleanup )
14
14
- [ ` removeCleanup ` ] ( /reference/api#removecleanup )
15
+ - [ ` console.error ` ] ( /reference/api#consoleerror )
15
16
16
17
---
17
18
@@ -154,7 +155,7 @@ module.exports = {
154
155
` ` `
155
156
156
157
Alternatively , you can change your test to import from ` @testing-library/react-hooks/pure ` instead
157
- of the regular imports. This applys to any of our export methods documented in
158
+ of the regular imports. This applies to any of our export methods documented in
158
159
[Rendering ](/installation #being -specific ).
159
160
160
161
` ` ` diff
@@ -270,3 +271,49 @@ Interval checking is disabled if `interval` is not provided as a `falsy`.
270
271
_Default: 1000_
271
272
272
273
The maximum amount of time in milliseconds (ms ) to wait.
274
+
275
+ ---
276
+
277
+ ## `console.error`
278
+
279
+ In order to catch errors that are produced in all parts of the hook's lifecycle, the test harness
280
+ used to wrap the hook call includes an
281
+ [Error Boundary](https : // reactjs.org/docs/error-boundaries.html) which causes a
282
+ [significant amount of output noise ](https : // reactjs.org/docs/error-boundaries.html#component-stack-traces)
283
+ in tests .
284
+
285
+ To keep test output clean , we patch ` console.error ` when ` renderHook ` is called to filter out the
286
+ unnecessary logging and restore the original version during cleanup. This side -effect can affect
287
+ tests that also patch ` console.error ` (e.g. to assert a specific error message get logged ) by
288
+ replacing their custom implementation as well .
289
+
290
+ ### Disabling ` console.error ` filtering
291
+
292
+ Importing ` @testing-library/react-hooks/disable-error-filtering.js ` in test setup files disable the
293
+ error filtering feature and not patch ` console.error ` in any way .
294
+
295
+ For example , in [Jest ](https : // jestjs.io/) this can be added to your
296
+ [Jest config ](https : // jestjs.io/docs/configuration):
297
+
298
+ ` ` ` js
299
+ module.exports = {
300
+ setupFilesAfterEnv: [
301
+ '@testing-library/react-hooks/disable-error-filtering.js'
302
+ // other setup files
303
+ ]
304
+ }
305
+ ` ` `
306
+
307
+ Alternatively , you can change your test to import from ` @testing-library/react-hooks/pure ` instead
308
+ of the regular imports. This applies to any of our export methods documented in
309
+ [Rendering ](/installation #being -specific ).
310
+
311
+ ` ` ` diff
312
+ - import { renderHook, cleanup, act } from '@testing-library/react-hooks'
313
+ + import { renderHook, cleanup, act } from '@testing-library/react-hooks/pure'
314
+ ` ` `
315
+
316
+ If neither of these approaches are suitable , setting the ` RHTL_DISABLE_ERROR_FILTERING ` environment
317
+ variable to ` true ` before importing ` @testing-library/react-hooks ` will also disable this feature.
318
+
319
+ > Please note that this may result is a significant amount of additional logging in you test output.
0 commit comments