diff --git a/packages/e2e-tests/plugins/interactive-blocks/deferred-store/view.js b/packages/e2e-tests/plugins/interactive-blocks/deferred-store/view.js index 121727dcc467c..d3803788c0d1b 100644 --- a/packages/e2e-tests/plugins/interactive-blocks/deferred-store/view.js +++ b/packages/e2e-tests/plugins/interactive-blocks/deferred-store/view.js @@ -3,8 +3,9 @@ */ import { store, getContext } from '@wordpress/interactivity'; -document.addEventListener( 'DOMContentLoaded', () => { - setTimeout( () => { +window.addEventListener( + '_test_proceed_', + () => { store( 'test/deferred-store', { state: { reversedText() { @@ -16,5 +17,6 @@ document.addEventListener( 'DOMContentLoaded', () => { }, }, } ); - }, 100 ); -} ); + }, + { once: true } +); diff --git a/test/e2e/specs/interactivity/deferred-store.spec.ts b/test/e2e/specs/interactivity/deferred-store.spec.ts index 4521322e61dfc..b6a7853c40dcd 100644 --- a/test/e2e/specs/interactivity/deferred-store.spec.ts +++ b/test/e2e/specs/interactivity/deferred-store.spec.ts @@ -21,6 +21,9 @@ test.describe( 'deferred store', () => { } ) => { const resultInput = page.getByTestId( 'result' ); await expect( resultInput ).toHaveText( '' ); + await page.evaluate( () => { + window.dispatchEvent( new Event( '_test_proceed_' ) ); + } ); await expect( resultInput ).toHaveText( 'Hello, world!' ); } ); @@ -31,6 +34,9 @@ test.describe( 'deferred store', () => { } ) => { const resultInput = page.getByTestId( 'result-getter' ); await expect( resultInput ).toHaveText( '' ); + await page.evaluate( () => { + window.dispatchEvent( new Event( '_test_proceed_' ) ); + } ); await expect( resultInput ).toHaveText( 'Hello, world!' ); } ); } );