From 911d3efd31c85be2fdffb05f1ffca88af57ccd84 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com> Date: Mon, 26 Oct 2026 15:06:10 -0400 Subject: [PATCH] Wait for the Typewriter in the TypeWriter E2E test's scroll case. --- .../specs/editor/various/typewriter.test.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/e2e-tests/specs/editor/various/typewriter.test.js b/packages/e2e-tests/specs/editor/various/typewriter.test.js index 2661d69acd9055..3d0abb44b3ef75 100644 --- a/packages/e2e-tests/specs/editor/various/typewriter.test.js +++ b/packages/e2e-tests/specs/editor/various/typewriter.test.js @@ -103,11 +103,32 @@ describe( 'TypeWriter', () => { ).scrollTop = 1 ) ); + /* + * The scroll event fires on the next animation frame, and the + * Typewriter recalculates the caret rectangle in an animation frame + * of its own after that, so wait two frames before reading it. + */ + await page.evaluate( + () => + new Promise( ( resolve ) => + window.requestAnimationFrame( () => + window.requestAnimationFrame( resolve ) + ) + ) + ); + const initialPosition = await getCaretPosition(); // Should maintain scroll position. await page.keyboard.press( 'Enter' ); + // Wait for the Typewriter to scroll down past the initial position. + await page.waitForFunction( + () => + wp.dom.getScrollContainer( document.activeElement ).scrollTop > + 1 + ); + expect( await getDiff( initialPosition ) ).toBeLessThanOrEqual( BUFFER );