@@ -124,6 +124,22 @@ describe('lib/index.ts', () => {
124124 expect ( await queries . getNodeText ( element ) ) . toEqual ( 'Hello h1' )
125125 } )
126126
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+
127143 describe ( 'configuration' , ( ) => {
128144 afterEach ( ( ) => {
129145 configure ( { testIdAttribute : 'data-testid' } ) // cleanup
@@ -148,34 +164,42 @@ describe('lib/index.ts', () => {
148164 'should keep the default data-testid when input passed is invalid (%s)' ,
149165 async options => {
150166 const document = await getDocument ( page )
167+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
151168 configure ( options as any )
152169 const element = await queries . getByTestId ( document , 'testid-label' )
153170 expect ( await queries . getNodeText ( element ) ) . toEqual ( 'Label A' )
154171 } ,
155172 )
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- } )
163173
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+ } )
171187 } )
172188
173189 describe ( 'loading the deferred page' , ( ) => {
174190 beforeEach ( async ( ) =>
175191 page . goto ( `file://${ path . join ( __dirname , '../fixtures/late-page.html' ) } ` ) ,
176192 )
177193
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 ( ) => {
179203 // FIXME: I think it will take some work to get the types in a
180204 // place to prevent @typescript -eslint from flagging this
181205 // eslint-disable-next-line @typescript-eslint/unbound-method
0 commit comments