@@ -124,6 +124,22 @@ describe('lib/index.ts', () => {
124
124
expect ( await queries . getNodeText ( element ) ) . toEqual ( 'Hello h1' )
125
125
} )
126
126
127
+ it ( 'should support regex on raw queries object' , async ( ) => {
128
+ const scope = await page . $ ( '#scoped' )
129
+ if ( ! scope ) throw new Error ( 'Should have scope' )
130
+ const element = await queries . getByText ( scope , / H e l l o / i)
131
+ expect ( await queries . getNodeText ( element ) ) . toEqual ( 'Hello h3' )
132
+ } )
133
+
134
+ it ( 'should bind getQueriesForElement' , async ( ) => {
135
+ // FIXME: I think it will take some work to get the types in a
136
+ // place to prevent @typescript -eslint from flagging this
137
+ // eslint-disable-next-line @typescript-eslint/unbound-method
138
+ const { getByText} = getQueriesForElement ( await getDocument ( page ) )
139
+ const element = await getByText ( 'Hello h1' )
140
+ expect ( await queries . getNodeText ( element ) ) . toEqual ( 'Hello h1' )
141
+ } )
142
+
127
143
describe ( 'configuration' , ( ) => {
128
144
afterEach ( ( ) => {
129
145
configure ( { testIdAttribute : 'data-testid' } ) // cleanup
@@ -148,34 +164,42 @@ describe('lib/index.ts', () => {
148
164
'should keep the default data-testid when input passed is invalid (%s)' ,
149
165
async options => {
150
166
const document = await getDocument ( page )
167
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
151
168
configure ( options as any )
152
169
const element = await queries . getByTestId ( document , 'testid-label' )
153
170
expect ( await queries . getNodeText ( element ) ) . toEqual ( 'Label A' )
154
171
} ,
155
172
)
156
- } )
157
- it ( 'should support regex on raw queries object' , async ( ) => {
158
- const scope = await page . $ ( '#scoped' )
159
- if ( ! scope ) throw new Error ( 'Should have scope' )
160
- const element = await queries . getByText ( scope , / H e l l o / i)
161
- expect ( await queries . getNodeText ( element ) ) . toEqual ( 'Hello h3' )
162
- } )
163
173
164
- it ( 'should bind getQueriesForElement' , async ( ) => {
165
- // FIXME: I think it will take some work to get the types in a
166
- // place to prevent @typescript -eslint from flagging this
167
- // eslint-disable-next-line @typescript-eslint/unbound-method
168
- const { getByText} = getQueriesForElement ( await getDocument ( page ) )
169
- const element = await getByText ( 'Hello h1' )
170
- expect ( await queries . getNodeText ( element ) ) . toEqual ( 'Hello h1' )
174
+ describe ( 'async utils timeout' , ( ) => {
175
+ beforeEach ( async ( ) =>
176
+ page . goto ( `file://${ path . join ( __dirname , '../fixtures/late-page.html' ) } ` ) ,
177
+ )
178
+
179
+ it ( 'supports configuring timeout for findBy* queries' , async ( ) => {
180
+ configure ( { asyncUtilTimeout : 9000 } )
181
+
182
+ const element = await queries . findByText ( await getDocument ( page ) , 'Loaded!' )
183
+
184
+ expect ( element ) . toBeTruthy ( )
185
+ } , 9000 )
186
+ } )
171
187
} )
172
188
173
189
describe ( 'loading the deferred page' , ( ) => {
174
190
beforeEach ( async ( ) =>
175
191
page . goto ( `file://${ path . join ( __dirname , '../fixtures/late-page.html' ) } ` ) ,
176
192
)
177
193
178
- it ( 'should use `wait` properly' , async ( ) => {
194
+ it ( 'waits for deferred element using findBy* queries' , async ( ) => {
195
+ const element = await queries . findByText ( await getDocument ( page ) , 'Loaded!' , undefined , {
196
+ timeout : 9000 ,
197
+ } )
198
+
199
+ expect ( element ) . toBeTruthy ( )
200
+ } , 9000 )
201
+
202
+ it ( 'waits for deferred element using `waitFor`' , async ( ) => {
179
203
// FIXME: I think it will take some work to get the types in a
180
204
// place to prevent @typescript -eslint from flagging this
181
205
// eslint-disable-next-line @typescript-eslint/unbound-method
0 commit comments