Skip to content

Commit 6b44453

Browse files
rubennortefacebook-github-bot
authored andcommitted
[skip ci] Add regression test for EventTarget (facebook#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: whatwg/dom#1346 Differential Revision: D67758702
1 parent 0441bc4 commit 6b44453

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

packages/react-native/src/private/webapis/dom/events/__tests__/EventTarget-itest.js

+48
Original file line numberDiff line numberDiff line change
@@ -926,5 +926,53 @@ describe('EventTarget', () => {
926926
expect(listenerThatWillBeRemoved).not.toHaveBeenCalled();
927927
});
928928
});
929+
930+
describe('re-attaching a previous listener with a pending signal', () => {
931+
// This is a regression test for https://github.com/whatwg/dom/issues/1346
932+
it('should remove the new subscription when the signal for the old subscription is aborted', () => {
933+
const [node] = createEventTargetHierarchyWithDepth(1);
934+
935+
// Listener setup
936+
937+
resetListenerCallOrder();
938+
939+
const listener = createListener();
940+
941+
const abortController = new AbortController();
942+
943+
node.addEventListener('custom', listener, {
944+
signal: abortController.signal,
945+
});
946+
947+
// Dispatch
948+
949+
const event = new Event('custom');
950+
951+
node.dispatchEvent(event);
952+
953+
expect(listener).toHaveBeenCalledTimes(1);
954+
955+
node.removeEventListener('custom', listener);
956+
957+
node.dispatchEvent(event);
958+
959+
expect(listener).toHaveBeenCalledTimes(1);
960+
961+
// Added without a signal
962+
node.addEventListener('custom', listener);
963+
964+
node.dispatchEvent(event);
965+
966+
// Listener is called
967+
expect(listener).toHaveBeenCalledTimes(2);
968+
969+
abortController.abort();
970+
971+
node.dispatchEvent(event);
972+
973+
// Listener is NOT called
974+
expect(listener).toHaveBeenCalledTimes(2);
975+
});
976+
});
929977
});
930978
});

0 commit comments

Comments
 (0)