Skip to content

Commit defcdab

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~~ __Chrome__: whatwg/dom#1346 Edit: the bug is in the Chrome implementation, not in the spec. Reviewed By: javache Differential Revision: D67758702
1 parent d143d64 commit defcdab

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
@@ -985,5 +985,53 @@ describe('EventTarget', () => {
985985
expect(listenerThatWillBeRemoved).not.toHaveBeenCalled();
986986
});
987987
});
988+
989+
describe('re-attaching a previous listener with a pending signal', () => {
990+
// This is a regression test for https://github.com/whatwg/dom/issues/1346
991+
it('should NOT remove the new subscription when the signal for the old subscription is aborted', () => {
992+
const [node] = createEventTargetHierarchyWithDepth(1);
993+
994+
// Listener setup
995+
996+
resetListenerCallOrder();
997+
998+
const listener = createListener();
999+
1000+
const abortController = new AbortController();
1001+
1002+
node.addEventListener('custom', listener, {
1003+
signal: abortController.signal,
1004+
});
1005+
1006+
// Dispatch
1007+
1008+
const event = new Event('custom');
1009+
1010+
node.dispatchEvent(event);
1011+
1012+
expect(listener).toHaveBeenCalledTimes(1);
1013+
1014+
node.removeEventListener('custom', listener);
1015+
1016+
node.dispatchEvent(event);
1017+
1018+
expect(listener).toHaveBeenCalledTimes(1);
1019+
1020+
// Added without a signal
1021+
node.addEventListener('custom', listener);
1022+
1023+
node.dispatchEvent(event);
1024+
1025+
// Listener is called
1026+
expect(listener).toHaveBeenCalledTimes(2);
1027+
1028+
abortController.abort();
1029+
1030+
node.dispatchEvent(event);
1031+
1032+
// Listener is called
1033+
expect(listener).toHaveBeenCalledTimes(3);
1034+
});
1035+
});
9881036
});
9891037
});

0 commit comments

Comments
 (0)