From 8cb3ba1f9889098e53cc9b8aa716cbaa4f4280de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Mon, 6 Jan 2025 09:25:38 -0800 Subject: [PATCH] [skip ci] 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~~ __Chrome__: https://github.com/whatwg/dom/issues/1346 Edit: the bug is in the Chrome implementation, not in the spec. 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..43dbc6d668b2d4 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 NOT 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 called + expect(listener).toHaveBeenCalledTimes(3); + }); + }); }); });