From 637ffd989f1bb630ca245ace19a5b5d2f95d1b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Fri, 3 Jan 2025 01:06:41 -0800 Subject: [PATCH] Add regression test for EventTarget (#48431) 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: https://github.com/whatwg/dom/issues/1346 Differential Revision: D67758702 --- .../dom/events/__tests__/EventTarget-itest.js | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/packages/react-native/src/private/webapis/dom/events/__tests__/EventTarget-itest.js b/packages/react-native/src/private/webapis/dom/events/__tests__/EventTarget-itest.js index 6d82f51e6890d3..bfb6048626ac08 100644 --- a/packages/react-native/src/private/webapis/dom/events/__tests__/EventTarget-itest.js +++ b/packages/react-native/src/private/webapis/dom/events/__tests__/EventTarget-itest.js @@ -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); + }); + }); }); });