1
1
import type { Locator , PlaywrightTestArgs , TestFixture } from '@playwright/test'
2
2
import { selectors } from '@playwright/test'
3
3
4
- import type { Config , LocatorQueries as Queries , SelectorEngine , SynchronousQuery } from '../types'
4
+ import type {
5
+ Config ,
6
+ LocatorQueries as Queries ,
7
+ SelectorEngine ,
8
+ SynchronousQuery ,
9
+ Within ,
10
+ } from '../types'
5
11
6
12
import {
7
13
buildTestingLibraryScript ,
@@ -11,16 +17,30 @@ import {
11
17
synchronousQueryNames ,
12
18
} from './helpers'
13
19
14
- const defaultConfig : Config = { testIdAttribute : 'data-testid' , asyncUtilTimeout : 1000 }
20
+ type TestArguments = PlaywrightTestArgs & Config
21
+
22
+ const defaultConfig : Config = {
23
+ asyncUtilExpectedState : 'visible' ,
24
+ asyncUtilTimeout : 1000 ,
25
+ testIdAttribute : 'data-testid' ,
26
+ }
15
27
16
28
const options = Object . fromEntries (
17
29
Object . entries ( defaultConfig ) . map ( ( [ key , value ] ) => [ key , [ value , { option : true } ] as const ] ) ,
18
30
)
19
31
20
- const queriesFixture : TestFixture < Queries , PlaywrightTestArgs > = async ( { page} , use ) =>
21
- use ( queriesFor ( page ) )
32
+ const queriesFixture : TestFixture < Queries , TestArguments > = async (
33
+ { page, asyncUtilExpectedState, asyncUtilTimeout} ,
34
+ use ,
35
+ ) => use ( queriesFor ( page , { asyncUtilExpectedState, asyncUtilTimeout} ) )
22
36
23
- const within = ( locator : Locator ) : Queries => queriesFor ( locator )
37
+ const withinFixture : TestFixture < Within , TestArguments > = async (
38
+ { asyncUtilExpectedState, asyncUtilTimeout} ,
39
+ use ,
40
+ ) =>
41
+ use (
42
+ ( locator : Locator ) : Queries => queriesFor ( locator , { asyncUtilExpectedState, asyncUtilTimeout} ) ,
43
+ )
24
44
25
45
declare const queryName : SynchronousQuery
26
46
@@ -82,18 +102,26 @@ const registerSelectorsFixture: [
82
102
]
83
103
84
104
const installTestingLibraryFixture : [
85
- TestFixture < void , PlaywrightTestArgs & Config > ,
105
+ TestFixture < void , TestArguments > ,
86
106
{ scope : 'test' ; auto ?: boolean } ,
87
107
] = [
88
- async ( { context, asyncUtilTimeout, testIdAttribute} , use ) => {
108
+ async ( { context, asyncUtilExpectedState , asyncUtilTimeout, testIdAttribute} , use ) => {
89
109
await context . addInitScript (
90
- await buildTestingLibraryScript ( { config : { asyncUtilTimeout, testIdAttribute} } ) ,
110
+ await buildTestingLibraryScript ( {
111
+ config : { asyncUtilExpectedState, asyncUtilTimeout, testIdAttribute} ,
112
+ } ) ,
91
113
)
92
114
93
115
await use ( )
94
116
} ,
95
117
{ scope : 'test' , auto : true } ,
96
118
]
97
119
98
- export { installTestingLibraryFixture , options , queriesFixture , registerSelectorsFixture , within }
120
+ export {
121
+ installTestingLibraryFixture ,
122
+ options ,
123
+ queriesFixture ,
124
+ registerSelectorsFixture ,
125
+ withinFixture ,
126
+ }
99
127
export type { Queries }
0 commit comments