@@ -10,6 +10,7 @@ import {
10
10
clearTimeout ,
11
11
} from './helpers'
12
12
import { getConfig , runWithExpensiveErrorDiagnosticsDisabled } from './config'
13
+ import { prettyDOM } from './pretty-dom'
13
14
14
15
// This is so the stack trace the developer sees is one that's
15
16
// closer to their code (because async stack traces are hard to follow).
@@ -25,6 +26,10 @@ function waitFor(
25
26
showOriginalStackTrace = getConfig ( ) . showOriginalStackTrace ,
26
27
stackTraceError,
27
28
interval = 50 ,
29
+ onTimeout = error => {
30
+ error . message = `${ error . message } \n\n${ prettyDOM ( container ) } `
31
+ return error
32
+ } ,
28
33
mutationObserverOptions = {
29
34
subtree : true ,
30
35
childList : true ,
@@ -41,7 +46,7 @@ function waitFor(
41
46
let lastError , intervalId , observer
42
47
let finished = false
43
48
44
- const overallTimeoutTimer = setTimeout ( onTimeout , timeout )
49
+ const overallTimeoutTimer = setTimeout ( handleTimeout , timeout )
45
50
46
51
const usingFakeTimers = jestFakeTimersAreEnabled ( )
47
52
if ( usingFakeTimers ) {
@@ -106,7 +111,7 @@ function waitFor(
106
111
}
107
112
}
108
113
109
- function onTimeout ( ) {
114
+ function handleTimeout ( ) {
110
115
let error
111
116
if ( lastError ) {
112
117
error = lastError
@@ -122,7 +127,7 @@ function waitFor(
122
127
copyStackTrace ( error , stackTraceError )
123
128
}
124
129
}
125
- onDone ( error , null )
130
+ onDone ( onTimeout ( error ) , null )
126
131
}
127
132
} )
128
133
}
0 commit comments