import * as SUT from '..' ; import { defaultWaitUntilOptions , WaitUntilOptions } from '../../../../utils' ; import { Browser , firefox } from 'playwright' ; describe ( 'get-handle-of' , ( ) : void => { let browser = undefined ; beforeEach ( ( ) : void => { } ) ; afterEach ( async ( ) : Promise < void > => { if ( browser ) { await browser . close ( ) ; } } ) ; test ( 'should return handle when selector exists on the page - firefox' , async ( ) : Promise < void > => { browser = await firefox . launch ( { headless : true } ) ; const context = await browser . newContext ( { viewport : null } ) ; const page = await context . newPage ( ) ; const result = await SUT . getHandleOf ( 'body' , page , defaultWaitUntilOptions ) ; expect ( result ) . toBeDefined ( ) ; } ) ; test ( 'should throw an error when selector does not exist on the page - firefox' , async ( ) : Promise < void > => { browser = await firefox . launch ( { headless : true } ) ; const context = await browser . newContext ( { viewport : null } ) ; const page = await context . newPage ( ) ; const options = { ... defaultWaitUntilOptions , timeoutInMilliseconds : 2000 , } ; let result = undefined ; try { await SUT . getHandleOf ( 'foobar' , page , options ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( "Selector 'foobar' was not found in DOM" ) ; } ) ; } ) ;