Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not throw on removeListener without listener #15224

Merged
merged 3 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/playwright-core/src/client/joiningEventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ export class JoiningEventEmitter implements EventEmitter {
}

private _wrapper(listener: (...args: any[]) => void) {
return (listener as any)[wrapperListener];
const wrapped = (listener as any)[wrapperListener];
mxschmitt marked this conversation as resolved.
Show resolved Hide resolved
// Fallback to original listener if not wrapped to ensure backwards compatibility Node.js's event emitter
if (!wrapped)
return listener;
return wrapped;
}

private _original(wrapper: Function): Function {
Expand Down
4 changes: 4 additions & 0 deletions tests/page/page-event-pageerror.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,7 @@ it('should handle window', async ({ page, browserName, isElectron }) => {
]);
expect(error.message).toBe(browserName === 'chromium' ? 'Window' : '[object Window]');
});

it('should remove a listener of a non-existing event handler', async ({ page }) => {
page.removeListener('pageerror', () => {});
});