import awaitNextFrame from "./awaitNextFrame" ; const setSizePlaceholder = async ( params ) => { } ; type SizeParams = { width ? : number ; height ? : number ; } ; type SetSizeFunction = ( params : SizeParams ) => Promise < void > ; const doSetSize = async ( element , params ) => { if ( ! element ) { return ; } if ( params . width ) { element . style . width = `${ params . width }px` ; } if ( params . height ) { element . style . height = `${ params . height }px` ; } await awaitNextFrame ( ) ; } ; export default function createController ( ) { let renderCount = 0 ; const incrementRenderCount = ( ) => renderCount ++ ; const assertRenderCount = ( count ) => expect ( renderCount ) . toBe ( count ) ; let measuredWidth ; let measuredHeight ; const reportMeasuredSize = ( params ) => { if ( typeof params . width === "number" || typeof params . width === "undefined" ) { measuredWidth = params . width ; } if ( typeof params . height === "number" || typeof params . height === "undefined" ) { measuredHeight = params . height ; } } ; const assertMeasuredSize = ( params ) => { expect ( measuredWidth ) . toBe ( params . width ) ; expect ( measuredHeight ) . toBe ( params . height ) ; } ; const controller = { incrementRenderCount , assertRenderCount , reportMeasuredSize , assertMeasuredSize , setSize : setSizePlaceholder , provideSetSizeFunction : ( ref ) => { } , triggerRender : async ( ) => { } , } ; controller . provideSetSizeFunction = ( element ) => { controller . setSize = ( params ) => doSetSize ( element , params ) ; } ; return controller ; }