File tree 4 files changed +22
-2
lines changed 4 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -343,6 +343,12 @@ Here are the accessible roles:
343
343
` )
344
344
} )
345
345
346
+ test ( 'has no useful error message in findBy' , async ( ) => {
347
+ const { findByRole} = render ( `<li />` )
348
+
349
+ await expect ( findByRole ( 'option' , { timeout : 1 } ) ) . rejects . toThrow ( 'Unable to find role="option"' )
350
+ } )
351
+
346
352
test ( 'explicit role is most specific' , ( ) => {
347
353
const { getByRole} = renderIntoDocument (
348
354
`<button role="tab" aria-label="my-tab" />` ,
Original file line number Diff line number Diff line change @@ -27,6 +27,16 @@ let config = {
27
27
error . name = 'TestingLibraryElementError'
28
28
return error
29
29
} ,
30
+ _disableExpensiveErrorDiagnostics : false ,
31
+ }
32
+
33
+ export function runWithExpensiveErrorDiagnosticsDisabled ( callback ) {
34
+ try {
35
+ config . _disableExpensiveErrorDiagnostics = true
36
+ return callback ( )
37
+ } finally {
38
+ config . _disableExpensiveErrorDiagnostics = false
39
+ }
30
40
}
31
41
32
42
export function configure ( newConfig ) {
Original file line number Diff line number Diff line change @@ -112,6 +112,10 @@ const getMissingError = (
112
112
role ,
113
113
{ hidden = getConfig ( ) . defaultHidden , name} = { } ,
114
114
) => {
115
+ if ( getConfig ( ) . _disableExpensiveErrorDiagnostics ) {
116
+ return `Unable to find role="${ role } "`
117
+ }
118
+
115
119
let roles = ''
116
120
Array . from ( container . children ) . forEach ( childElement => {
117
121
roles += prettyRoles ( childElement , {
Original file line number Diff line number Diff line change 6
6
clearTimeout ,
7
7
runWithRealTimers ,
8
8
} from './helpers'
9
- import { getConfig } from './config'
9
+ import { getConfig , runWithExpensiveErrorDiagnosticsDisabled } from './config'
10
10
11
11
// This is so the stack trace the developer sees is one that's
12
12
// closer to their code (because async stack traces are hard to follow).
@@ -60,7 +60,7 @@ function waitFor(
60
60
61
61
function checkCallback ( ) {
62
62
try {
63
- onDone ( null , callback ( ) )
63
+ onDone ( null , runWithExpensiveErrorDiagnosticsDisabled ( callback ) )
64
64
// If `callback` throws, wait for the next mutation or timeout.
65
65
} catch ( error ) {
66
66
// Save the callback error to reject the promise with it.
You can’t perform that action at this time.
0 commit comments