File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,7 @@ function createEventDescriptions(classDesc) {
141
141
const argName = argNameForType ( type ) ;
142
142
const params = argName ? `${ argName } : ${ type } ` : '' ;
143
143
descriptions . push ( {
144
+ type,
144
145
params,
145
146
eventName,
146
147
comment : value . comment
@@ -167,6 +168,16 @@ function classBody(classDesc) {
167
168
parts . push ( members . map ( member => {
168
169
if ( member . kind === 'event' )
169
170
return '' ;
171
+ if ( member . name === 'waitForEvent' ) {
172
+ const parts = [ ] ;
173
+ for ( const { eventName, params, comment, type} of eventDescriptions ) {
174
+ if ( comment )
175
+ parts . push ( writeComment ( comment , ' ' ) ) ;
176
+ parts . push ( ` ${ member . name } (event: '${ eventName } ', optionsOrPredicate?: { predicate?: (${ params } ) => boolean, timeout?: number }): Promise<${ type } >;\n` ) ;
177
+ }
178
+
179
+ return parts . join ( '\n' ) ;
180
+ }
170
181
const jsdoc = memberJSDOC ( member , ' ' ) ;
171
182
const args = argsFromMember ( member , classDesc . name ) ;
172
183
const type = typeToString ( member . type , classDesc . name , member . name ) ;
Original file line number Diff line number Diff line change @@ -290,6 +290,31 @@ playwright.chromium.launch().then(async browser => {
290
290
browser . close ( ) ;
291
291
} ) ( ) ;
292
292
293
+ // waitForEvent
294
+ ( async ( ) => {
295
+ const browser = await playwright . webkit . launch ( ) ;
296
+ const page = await browser . newPage ( ) ;
297
+ {
298
+ const frame = await page . waitForEvent ( 'frameattached' ) ;
299
+ const assertion : AssertType < playwright . Frame , typeof frame > = true ;
300
+ }
301
+ {
302
+ const worker = await page . waitForEvent ( 'worker' , {
303
+ predicate : worker => {
304
+ const condition : AssertType < playwright . Worker , typeof worker > = true ;
305
+ return true ;
306
+ }
307
+ } ) ;
308
+ const assertion : AssertType < playwright . Worker , typeof worker > = true ;
309
+ }
310
+ {
311
+ const newPage = await page . context ( ) . waitForEvent ( 'page' , {
312
+ timeout : 500
313
+ } ) ;
314
+ const assertion : AssertType < playwright . Page , typeof newPage > = true ;
315
+ }
316
+ } ) ( ) ;
317
+
293
318
// typed handles
294
319
( async ( ) => {
295
320
const browser = await playwright . webkit . launch ( ) ;
@@ -515,7 +540,6 @@ playwright.chromium.launch().then(async browser => {
515
540
}
516
541
}
517
542
518
-
519
543
await browser . close ( ) ;
520
544
} ) ( ) ;
521
545
You can’t perform that action at this time.
0 commit comments