fix: waitForRequest works with async predicate (#9058)

This commit is contained in:
Egor Andreyuk 2022-10-05 21:46:34 +03:00 committed by GitHub
parent a07ff121f0
commit 8f6b2c9b7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -1668,12 +1668,12 @@ export class CDPPage extends Page {
return waitForEvent(
this.#frameManager.networkManager,
NetworkManagerEmittedEvents.Request,
request => {
async request => {
if (isString(urlOrPredicate)) {
return urlOrPredicate === request.url();
}
if (typeof urlOrPredicate === 'function') {
return !!urlOrPredicate(request);
return !!(await urlOrPredicate(request));
}
return false;
},

View File

@ -907,6 +907,22 @@ describe('Page', function () {
]);
expect(request.url()).toBe(server.PREFIX + '/digits/2.png');
});
it('should work with async predicate', async () => {
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
const [request] = await Promise.all([
page.waitForRequest(async request => {
return request.url() === server.PREFIX + '/digits/2.png';
}),
page.evaluate(() => {
fetch('/digits/1.png');
fetch('/digits/2.png');
fetch('/digits/3.png');
}),
]);
expect(request.url()).toBe(server.PREFIX + '/digits/2.png');
});
it('should respect timeout', async () => {
const {page, puppeteer} = getTestState();