Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions core/src/tests/web-plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,29 @@ describe('Web Plugin', () => {
expect(handlerFunction).not.toHaveBeenCalled();
});

it('Should re-register window listeners after removeAllListeners', async () => {
plugin.registerFakeWindowListener();

const lf1 = jest.fn();
await plugin.addListener('test', lf1);
await plugin.removeAllListeners();

const lf2 = jest.fn();
const handle = await plugin.addListener('test', lf2);

const windowListener = plugin.getWindowListeners()['test'];
expect(windowListener).not.toBe(undefined);
expect(windowListener.registered).toEqual(true);

window.dispatchEvent(new CustomEvent('fake', { detail: { value: 'after removeAll' } }));

expect(lf1).not.toHaveBeenCalled();
expect(lf2.mock.calls.length).toEqual(1);
expect(lf2.mock.calls[0][0].detail.value).toEqual('after removeAll');

await handle.remove();
});

it('Should not remove a listener if it is not found', async () => {
const lf1 = (event: any) => {
console.log(event);
Expand Down
1 change: 0 additions & 1 deletion core/src/web-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export class WebPlugin implements Plugin {
for (const listener in this.windowListeners) {
this.removeWindowListener(this.windowListeners[listener]);
}
this.windowListeners = {};
}

protected notifyListeners(eventName: string, data: any, retainUntilConsumed?: boolean): void {
Expand Down