1
1
import { prettyDOM } from './pretty-dom'
2
+ import { Callback } from './types'
3
+
4
+ export interface Config {
5
+ testIdAttribute : string
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ asyncWrapper ( cb : ( ...args : any [ ] ) => any ) : Promise < any >
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ eventWrapper ( cb : ( ...args : any [ ] ) => any ) : void
10
+ asyncUtilTimeout : number
11
+ computedStyleSupportsPseudoElements : boolean
12
+ defaultHidden : boolean
13
+ showOriginalStackTrace : boolean
14
+ throwSuggestions : boolean
15
+ getElementError : ( message : string | null , container : Element ) => Error
16
+ }
17
+
18
+ export interface ConfigFn {
19
+ ( existingConfig : Config ) : Partial < Config >
20
+ }
21
+
22
+ interface InternalConfig {
23
+ _disableExpensiveErrorDiagnostics : boolean
24
+ }
2
25
3
26
// It would be cleaner for this to live inside './queries', but
4
27
// other parts of the code assume that all exports from
5
28
// './queries' are query functions.
6
- let config = {
29
+ let config : Config & InternalConfig = {
7
30
testIdAttribute : 'data-testid' ,
8
31
asyncUtilTimeout : 1000 ,
9
32
// this is to support React's async `act` function.
@@ -36,7 +59,9 @@ let config = {
36
59
}
37
60
38
61
export const DEFAULT_IGNORE_TAGS = 'script, style'
39
- export function runWithExpensiveErrorDiagnosticsDisabled ( callback ) {
62
+ export function runWithExpensiveErrorDiagnosticsDisabled < T > (
63
+ callback : Callback < T > ,
64
+ ) {
40
65
try {
41
66
config . _disableExpensiveErrorDiagnostics = true
42
67
return callback ( )
@@ -45,7 +70,7 @@ export function runWithExpensiveErrorDiagnosticsDisabled(callback) {
45
70
}
46
71
}
47
72
48
- export function configure ( newConfig ) {
73
+ export function configure ( newConfig : Partial < Config > | ConfigFn ) {
49
74
if ( typeof newConfig === 'function' ) {
50
75
// Pass the existing config out to the provided function
51
76
// and accept a delta in return
0 commit comments