Skip to content

Commit

Permalink
Fix flaky test by finalising request resolution in Nav block e2e test (
Browse files Browse the repository at this point in the history
…#39633)

* Conditionalise resolution function

* Try calling request.continue to finalise request
  • Loading branch information
getdave authored Mar 28, 2022
1 parent bdd024e commit 081640b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/e2e-tests/specs/editor/blocks/navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,17 +356,20 @@ describe( 'Navigation', () => {
await setUpResponseMocking( [
{
match: ( request ) =>
request.method() === 'GET' &&
request.url().includes( `rest_route` ) &&
request.url().includes( `navigation` ) &&
request.url().includes( testNavId ),
onRequestMatch: () => {
onRequestMatch: ( request ) => {
// The Promise simulates a REST API request whose resolultion
// the test has full control over.
return new Promise( ( resolve ) => {
// Assign the resolution function to the var in the
// upper scope to afford control over resolution.
resolveNavigationRequest = resolve;
} );

// Call request.continue() is required to fully resolve the mock.
} ).then( () => request.continue() );
},
},
] );
Expand All @@ -390,7 +393,9 @@ describe( 'Navigation', () => {
await navBlock.waitForSelector( '.components-spinner' );

// Resolve the controlled mocked API request.
resolveNavigationRequest();
if ( typeof resolveNavigationRequest === 'function' ) {
resolveNavigationRequest();
}
} );

it( 'shows a loading indicator whilst empty Navigation menu is being created', async () => {
Expand All @@ -408,14 +413,16 @@ describe( 'Navigation', () => {
request.url().includes( `rest_route` ) &&
request.url().includes( `navigation` ) &&
request.url().includes( testNavId ),
onRequestMatch: () => {
onRequestMatch: ( request ) => {
// The Promise simulates a REST API request whose resolultion
// the test has full control over.
return new Promise( ( resolve ) => {
// Assign the resolution function to the var in the
// upper scope to afford control over resolution.
resolveNavigationRequest = resolve;
} );

// Call request.continue() is required to fully resolve the mock.
} ).then( () => request.continue() );
},
},
] );
Expand All @@ -437,7 +444,9 @@ describe( 'Navigation', () => {
await navBlock.waitForSelector( '.components-spinner' );

// Resolve the controlled mocked API request.
resolveNavigationRequest();
if ( typeof resolveNavigationRequest === 'function' ) {
resolveNavigationRequest();
}
} );
} );

Expand Down

0 comments on commit 081640b

Please sign in to comment.