test(op_crates/web): add EventTarget tests (#8205)

This commit is contained in:
Benjamin Gruenbaum 2020-11-02 19:42:22 +02:00 committed by GitHub
parent 0e5c8c03ac
commit a8ca9fe7bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View file

@ -223,3 +223,23 @@ unitTest(
assertEquals(callCount, 2);
},
);
unitTest(function eventTargetDispatchShouldSetTargetNoListener(): void {
const target = new EventTarget();
const event = new Event("foo");
assertEquals(event.target, null);
target.dispatchEvent(event);
assertEquals(event.target, target);
});
unitTest(function eventTargetDispatchShouldSetTargetInListener(): void {
const target = new EventTarget();
const event = new Event("foo");
assertEquals(event.target, null);
let called = false;
target.addEventListener("foo", (e) => {
assertEquals(e.target, target);
called = true;
});
target.dispatchEvent(event);
assertEquals(called, true);
});

View file

@ -936,6 +936,7 @@
const listeners = eventTargetData.get(self).listeners;
if (!(event.type in listeners)) {
setTarget(event, this);
return true;
}