@@ -1178,3 +1178,51 @@ test('should record trace for manually created context in a failed test', async
11781178 // Check console events to make sure that library trace is recorded.
11791179 expect ( trace . events ) . toContainEqual ( expect . objectContaining ( { type : 'console' , text : 'from the page' } ) ) ;
11801180} ) ;
1181+
1182+ test ( 'should not nest top level expect into unfinished api calls ' , {
1183+ annotation : { type : 'issue' , description : 'https://github.com/microsoft/playwright/issues/31959' }
1184+ } , async ( { runInlineTest, server } ) => {
1185+ server . setRoute ( '/index' , ( req , res ) => {
1186+ res . writeHead ( 200 , { 'Content-Type' : 'text/html' } ) ;
1187+ res . end ( `<script>fetch('/api')</script><div>Hello!</div>` ) ;
1188+ } ) ;
1189+ server . setRoute ( '/hang' , ( ) => { } ) ;
1190+ const result = await runInlineTest ( {
1191+ 'a.spec.ts' : `
1192+ import { test, expect } from '@playwright/test';
1193+ test('pass', async ({ page }) => {
1194+ await page.route('**/api', async route => {
1195+ const response = await route.fetch({ url: '${ server . PREFIX } /hang' });
1196+ await route.fulfill({ response });
1197+ });
1198+ await page.goto('${ server . PREFIX } /index');
1199+ await expect(page.getByText('Hello!')).toBeVisible();
1200+ await page.unrouteAll({ behavior: 'ignoreErrors' });
1201+ });
1202+ ` ,
1203+ } , { trace : 'on' } ) ;
1204+ expect ( result . exitCode ) . toBe ( 0 ) ;
1205+ expect ( result . failed ) . toBe ( 0 ) ;
1206+
1207+ const tracePath = test . info ( ) . outputPath ( 'test-results' , 'a-pass' , 'trace.zip' ) ;
1208+ const trace = await parseTrace ( tracePath ) ;
1209+ expect ( trace . actionTree ) . toEqual ( [
1210+ 'Before Hooks' ,
1211+ ' fixture: browser' ,
1212+ ' browserType.launch' ,
1213+ ' fixture: context' ,
1214+ ' browser.newContext' ,
1215+ ' fixture: page' ,
1216+ ' browserContext.newPage' ,
1217+ 'page.route' ,
1218+ 'page.goto' ,
1219+ ' route.fetch' ,
1220+ ' page.unrouteAll' ,
1221+ 'expect.toBeVisible' ,
1222+ 'After Hooks' ,
1223+ ' fixture: page' ,
1224+ ' fixture: context' ,
1225+ ] ) ;
1226+ } ) ;
1227+
1228+
0 commit comments