fix(types): add missing types for removing event listeners (#2307)

This commit is contained in:
Joel Einbinder 2020-05-20 07:34:36 -07:00 committed by GitHub
parent e558f0516b
commit 8e396fdac0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

@ -159,7 +159,7 @@ function createEventDescriptions(classDesc) {
function classBody(classDesc) {
const parts = [];
const eventDescriptions = createEventDescriptions(classDesc);
for (const method of ['on', 'once', 'addListener']) {
for (const method of ['on', 'once', 'addListener', 'removeListener', 'off']) {
for (const {eventName, params, comment} of eventDescriptions) {
if (comment)
parts.push(writeComment(comment, ' '));

View file

@ -88,6 +88,7 @@ playwright.chromium.launch().then(async browser => {
import * as crypto from 'crypto';
import * as fs from 'fs';
import { EventEmitter } from 'events';
playwright.chromium.launch().then(async browser => {
const page = await browser.newPage();
@ -729,3 +730,14 @@ playwright.chromium.launch().then(async browser => {
// Register the engine. Selectors will be prefixed with "tag=".
await playwright.selectors.register('tag', createTagNameEngine);
})();
// Event listeners
(async function() {
const eventEmitter = {} as (playwright.Page|playwright.BrowserContext|EventEmitter);
const listener = () => {};
eventEmitter.addListener('close', listener)
.on('close', listener)
.once('close', listener)
.removeListener('close', listener)
.off('close', listener);
});