@@ -176,6 +176,8 @@ describe('lib/index.ts', () => {
176176 page . goto ( `file://${ path . join ( __dirname , '../fixtures/late-page.html' ) } ` ) ,
177177 )
178178
179+ afterEach ( async ( ) => page . goto ( `file://${ path . join ( __dirname , '../fixtures/page.html' ) } ` ) )
180+
179181 it ( 'supports configuring timeout for findBy* queries' , async ( ) => {
180182 configure ( { asyncUtilTimeout : 9000 } )
181183
@@ -186,31 +188,40 @@ describe('lib/index.ts', () => {
186188 } )
187189 } )
188190
189- describe ( 'loading the deferred page' , ( ) => {
190- beforeEach ( async ( ) =>
191- page . goto ( `file://${ path . join ( __dirname , '../fixtures/late-page.html' ) } ` ) ,
192- )
193-
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- } )
191+ afterAll ( async ( ) => {
192+ await browser . close ( )
193+ } )
194+ } )
198195
199- expect ( element ) . toBeTruthy ( )
200- } , 9000 )
196+ describe ( 'loading the deferred page' , ( ) => {
197+ let browser : playwright . Browser
198+ let page : playwright . Page
201199
202- it ( 'waits for deferred element using `waitFor`' , async ( ) => {
203- // FIXME: I think it will take some work to get the types in a
204- // place to prevent @typescript -eslint from flagging this
205- // eslint-disable-next-line @typescript-eslint/unbound-method
206- const { getByText} = getQueriesForElement ( await getDocument ( page ) )
207- // eslint-disable-next-line @typescript-eslint/no-misused-promises
208- await waitFor ( async ( ) => expect ( await getByText ( 'Loaded!' ) ) . toBeTruthy ( ) , { timeout : 7000 } )
209- expect ( await getByText ( 'Loaded!' ) ) . toBeTruthy ( )
210- } , 9000 )
200+ beforeEach ( async ( ) => {
201+ browser = await playwright . firefox . launch ( )
202+ page = await browser . newPage ( )
203+ return page . goto ( `file://${ path . join ( __dirname , '../fixtures/late-page.html' ) } ` )
211204 } )
212205
213- afterAll ( async ( ) => {
206+ afterEach ( async ( ) => {
214207 await browser . close ( )
215208 } )
209+
210+ it ( 'waits for deferred element using findBy* queries' , async ( ) => {
211+ const element = await queries . findByText ( await getDocument ( page ) , 'Loaded!' , undefined , {
212+ timeout : 9000 ,
213+ } )
214+
215+ expect ( element ) . toBeTruthy ( )
216+ } , 9000 )
217+
218+ it ( 'waits for deferred element using `waitFor`' , async ( ) => {
219+ // FIXME: I think it will take some work to get the types in a
220+ // place to prevent @typescript -eslint from flagging this
221+ // eslint-disable-next-line @typescript-eslint/unbound-method
222+ const { getByText} = getQueriesForElement ( await getDocument ( page ) )
223+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
224+ await waitFor ( async ( ) => expect ( await getByText ( 'Loaded!' ) ) . toBeTruthy ( ) , { timeout : 7000 } )
225+ expect ( await getByText ( 'Loaded!' ) ) . toBeTruthy ( )
226+ } , 9000 )
216227} )
0 commit comments