File tree Expand file tree Collapse file tree 3 files changed +27
-4
lines changed Expand file tree Collapse file tree 3 files changed +27
-4
lines changed Original file line number Diff line number Diff line change 1
1
import { waitFor } from '../'
2
+ import { configure , getConfig } from '../config'
2
3
import { renderIntoDocument } from './helpers/test-utils'
3
4
4
5
test ( 'waits callback to not throw an error' , async ( ) => {
@@ -125,3 +126,22 @@ test('timeout logs a pretty DOM', async () => {
125
126
</html>"
126
127
` )
127
128
} )
129
+
130
+ test ( 'should delegate to config.getElementError' , async ( ) => {
131
+ const originalConfig = getConfig ( )
132
+ const elementError = new Error ( 'Custom element error' )
133
+ const getElementError = jest . fn ( ) . mockImplementation ( ( ) => elementError )
134
+ configure ( { getElementError} )
135
+
136
+ renderIntoDocument ( `<div id="pretty">how pretty</div>` )
137
+ const error = await waitFor (
138
+ ( ) => {
139
+ throw new Error ( 'always throws' )
140
+ } ,
141
+ { timeout : 1 } ,
142
+ ) . catch ( e => e )
143
+
144
+ expect ( getElementError ) . toBeCalledTimes ( 1 )
145
+ expect ( error . message ) . toMatchInlineSnapshot ( `"Custom element error"` )
146
+ configure ( originalConfig )
147
+ } )
Original file line number Diff line number Diff line change 1
- import { prettyDOM } from './pretty-dom'
2
1
import { getSuggestedQuery } from './suggestions'
3
2
import { fuzzyMatches , matches , makeNormalizer } from './matches'
4
3
import { waitFor } from './wait-for'
@@ -46,7 +45,9 @@ function makeSingleQuery(allQuery, getMultipleError) {
46
45
return ( container , ...args ) => {
47
46
const els = allQuery ( container , ...args )
48
47
if ( els . length > 1 ) {
49
- const elementStrings = els . map ( element => prettyDOM ( element ) ) . join ( '\n\n' )
48
+ const elementStrings = els
49
+ . map ( element => getElementError ( null , element ) . message )
50
+ . join ( '\n\n' )
50
51
51
52
throw getMultipleElementsFoundError (
52
53
`${ getMultipleError ( container , ...args ) }
Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ import {
10
10
clearTimeout ,
11
11
} from './helpers'
12
12
import { getConfig , runWithExpensiveErrorDiagnosticsDisabled } from './config'
13
- import { prettyDOM } from './pretty-dom'
14
13
15
14
// This is so the stack trace the developer sees is one that's
16
15
// closer to their code (because async stack traces are hard to follow).
@@ -27,7 +26,10 @@ function waitFor(
27
26
stackTraceError,
28
27
interval = 50 ,
29
28
onTimeout = error => {
30
- error . message = `${ error . message } \n\n${ prettyDOM ( container ) } `
29
+ error . message = getConfig ( ) . getElementError (
30
+ error . message ,
31
+ container ,
32
+ ) . message
31
33
return error
32
34
} ,
33
35
mutationObserverOptions = {
You can’t perform that action at this time.
0 commit comments