Skip to content

Commit

Permalink
[skip ci] Add regression test for EventTarget (facebook#48431)
Browse files Browse the repository at this point in the history
Summary:

Changelog: [internal]

Adds a regression test to make sure we implement the correct spec-compliant behavior for a possible bug in the Web spec: whatwg/dom#1346

Differential Revision: D67758702
  • Loading branch information
rubennorte authored and facebook-github-bot committed Jan 3, 2025
1 parent 673901e commit f6b5894
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -926,5 +926,53 @@ describe('EventTarget', () => {
expect(listenerThatWillBeRemoved).not.toHaveBeenCalled();
});
});

describe('re-attaching a previous listener with a pending signal', () => {
// This is a regression test for https://github.com/whatwg/dom/issues/1346
it('should remove the new subscription when the signal for the old subscription is aborted', () => {
const [node] = createEventTargetHierarchyWithDepth(1);

// Listener setup

resetListenerCallOrder();

const listener = createListener();

const abortController = new AbortController();

node.addEventListener('custom', listener, {
signal: abortController.signal,
});

// Dispatch

const event = new Event('custom');

node.dispatchEvent(event);

expect(listener).toHaveBeenCalledTimes(1);

node.removeEventListener('custom', listener);

node.dispatchEvent(event);

expect(listener).toHaveBeenCalledTimes(1);

// Added without a signal
node.addEventListener('custom', listener);

node.dispatchEvent(event);

// Listener is called
expect(listener).toHaveBeenCalledTimes(2);

abortController.abort();

node.dispatchEvent(event);

// Listener is NOT called
expect(listener).toHaveBeenCalledTimes(2);
});
});
});
});

0 comments on commit f6b5894

Please sign in to comment.