Commit 7d99007b authored by David Sveningsson's avatar David Sveningsson
Browse files

feat: add `isSameNode()`

parent 826c9d38
Pipeline #295945021 passed with stages
in 12 minutes and 9 seconds
......@@ -61,6 +61,21 @@ describe("DOMNode", () => {
});
});
describe("isSameNode()", () => {
const a = new DOMNode(NodeType.ELEMENT_NODE, "div", location);
const b = new DOMNode(NodeType.ELEMENT_NODE, "div", location);
it("should return true if the element references the same node", () => {
expect.assertions(1);
expect(a.isSameNode(a)).toBeTruthy();
});
it("should return false if the element is another node", () => {
expect.assertions(1);
expect(a.isSameNode(b)).toBeFalsy();
});
});
describe("firstChild", () => {
it("should return first child if present", () => {
expect.assertions(1);
......
......@@ -142,6 +142,13 @@ export class DOMNode {
return this.nodeType === NodeType.DOCUMENT_NODE;
}
/**
* Tests if two nodes are the same (references the same object).
*/
public isSameNode(otherNode: DOMNode): boolean {
return this.unique === otherNode.unique;
}
/**
* Returns a DOMNode representing the first direct child node or `null` if the
* node has no children.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment