import * as SUT from '../index' ; import { getViewportRectangleOf } from '../../../page-actions' ; import { Browser , chromium , ElementHandle } from 'playwright' ; describe ( 'scroll to handle' , ( ) : void => { let browser = undefined ; beforeEach ( ( ) : void => { } ) ; afterEach ( async ( ) : Promise < void > => { if ( browser ) { await browser . close ( ) ; } } ) ; test ( 'should do nothing when handle is undefined' , async ( ) : Promise < void > => { browser = await chromium . launch ( { headless : true } ) ; const browserContext = await browser . newContext ( { viewport : null } ) ; const page = await browserContext . newPage ( ) ; const handle = undefined ; const previousViewportRectangle = await getViewportRectangleOf ( page ) ; await SUT . scrollToHandle ( handle ) ; const currentViewportRectangle = await getViewportRectangleOf ( page ) ; expect ( previousViewportRectangle ) . toMatchObject ( currentViewportRectangle || { } ) ; } ) ; test ( 'should do nothing when handle is null' , async ( ) : Promise < void > => { browser = await chromium . launch ( { headless : true } ) ; const browserContext = await browser . newContext ( { viewport : null } ) ; const page = await browserContext . newPage ( ) ; const handle = null ; const previousViewportRectangle = await getViewportRectangleOf ( page ) ; await SUT . scrollToHandle ( handle ) ; const currentViewportRectangle = await getViewportRectangleOf ( page ) ; expect ( previousViewportRectangle ) . toMatchObject ( currentViewportRectangle || { } ) ; } ) ; } ) ;