Skip to content

Commit 560d322

Browse files
committed
feat(test): add mock for Node.contains()
1 parent 8b4597c commit 560d322

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/mock-doc/node.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ export class MockNode {
103103
return null;
104104
}
105105

106+
contains(otherNode: MockNode) {
107+
return this.childNodes.includes(otherNode);
108+
}
109+
106110
removeChild(childNode: MockNode) {
107111
const index = this.childNodes.indexOf(childNode);
108112
if (index > -1) {

src/mock-doc/test/element.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ describe('element', () => {
1111
const elmParent = document.createElement('div');
1212
const elmChild = document.createElement('div');
1313
elmParent.appendChild(elmChild);
14+
expect(document.body.contains(elmParent)).toBe(false);
1415
document.body.appendChild(elmParent);
16+
expect(document.body.contains(elmParent)).toBe(true);
1517
expect(elmParent.isConnected).toBe(true);
1618
expect(elmChild.isConnected).toBe(true);
1719
expect(document.body.isConnected).toBe(true);

0 commit comments

Comments
 (0)