Skip to content

Commit 8e396fd

Browse files
fix(types): add missing types for removing event listeners (#2307)
1 parent e558f05 commit 8e396fd

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

utils/generate_types/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ function createEventDescriptions(classDesc) {
159159
function classBody(classDesc) {
160160
const parts = [];
161161
const eventDescriptions = createEventDescriptions(classDesc);
162-
for (const method of ['on', 'once', 'addListener']) {
162+
for (const method of ['on', 'once', 'addListener', 'removeListener', 'off']) {
163163
for (const {eventName, params, comment} of eventDescriptions) {
164164
if (comment)
165165
parts.push(writeComment(comment, ' '));

utils/generate_types/test/test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ playwright.chromium.launch().then(async browser => {
8888

8989
import * as crypto from 'crypto';
9090
import * as fs from 'fs';
91+
import { EventEmitter } from 'events';
9192

9293
playwright.chromium.launch().then(async browser => {
9394
const page = await browser.newPage();
@@ -729,3 +730,14 @@ playwright.chromium.launch().then(async browser => {
729730
// Register the engine. Selectors will be prefixed with "tag=".
730731
await playwright.selectors.register('tag', createTagNameEngine);
731732
})();
733+
734+
// Event listeners
735+
(async function() {
736+
const eventEmitter = {} as (playwright.Page|playwright.BrowserContext|EventEmitter);
737+
const listener = () => {};
738+
eventEmitter.addListener('close', listener)
739+
.on('close', listener)
740+
.once('close', listener)
741+
.removeListener('close', listener)
742+
.off('close', listener);
743+
});

0 commit comments

Comments
 (0)