Skip to content

Commit

Permalink
Add test for event listeners on cloneNode
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Hillesö committed Jan 14, 2025
1 parent 543cc8d commit e824147
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 0 additions & 1 deletion lib/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ module.exports = class Element extends Node {
}
cloneNode(deep) {
const $clone = this.$elm.clone();
// TODO check for event listeners, should be empty on $clone
if (!deep) {
$clone.empty();
}
Expand Down
10 changes: 9 additions & 1 deletion test/elements-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const HTMLAnchorElement = require("../lib/HTMLAnchorElement.js");
const HTMLFormElement = require("../lib/HTMLFormElement.js");
const { Document } = require("../lib/index.js");
const { Event } = require("../lib/Events.js");
const { expect } = require("chai");

const elementProperties = [
"children",
Expand Down Expand Up @@ -1489,6 +1488,15 @@ describe("elements", () => {

expect(elmCloneChild === elmChild).to.be.false;
});

it("returns a clone without event listerners", () => {
const elm = document.getElementsByClassName("block")[0];
let clicked = false;
elm.addEventListener("click", () => (clicked = true));
const elmClone = elm.cloneNode(true);
elmClone.click();
expect(clicked).to.be.false;
});
});

describe("video element", () => {
Expand Down

0 comments on commit e824147

Please sign in to comment.