Skip to content

Commit

Permalink
#960@trivial: Adds unit tests for testing that children and childNode…
Browse files Browse the repository at this point in the history
…s are getters.
  • Loading branch information
capricorn86 committed Aug 22, 2023
1 parent 0b31097 commit 28f9b72
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ describe('DocumentFragment', () => {
documentFragment.appendChild(span);
expect(Array.from(documentFragment.children)).toEqual([div, span]);
});

it('Is a getter.', () => {
expect(
typeof Object.getOwnPropertyDescriptor(DocumentFragment.prototype, 'children')?.get
).toBe('function');
});
});

describe('get childElementCount()', () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/happy-dom/test/nodes/document/Document.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import NodeIterator from '../../../src/tree-walker/NodeIterator.js';
import TreeWalker from '../../../src/tree-walker/TreeWalker.js';
import Node from '../../../src/nodes/node/Node.js';
import IDocument from '../../../src/nodes/document/IDocument.js';
import Document from '../../../src/nodes/document/Document.js';
import Element from '../../../src/nodes/element/Element.js';
import Event from '../../../src/event/Event.js';
import SVGSVGElement from '../../../src/nodes/svg-element/SVGSVGElement.js';
Expand Down Expand Up @@ -77,6 +78,12 @@ describe('Document', () => {
expect(document.children.length).toEqual(1);
expect(document.children[0] === document.documentElement).toBe(true);
});

it('Is a getter.', () => {
expect(typeof Object.getOwnPropertyDescriptor(Document.prototype, 'children')?.get).toBe(
'function'
);
});
});

describe('get links()', () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/happy-dom/test/nodes/element/Element.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import HTMLTemplateElement from '../../../src/nodes/html-template-element/HTMLTe
import Node from '../../../src/nodes/node/Node.js';
import IHTMLCollection from '../../../src/nodes/element/IHTMLCollection.js';
import IElement from '../../../src/nodes/element/IElement.js';
import Element from '../../../src/nodes/element/Element.js';
import INodeList from '../../../src/nodes/node/INodeList.js';
import IAttr from '../../../src/nodes/attr/IAttr.js';
import Event from '../../../src/event/Event.js';
Expand Down Expand Up @@ -52,6 +53,12 @@ describe('Element', () => {
expect(element.children[0] === div1).toBe(true);
expect(element.children[1] === div2).toBe(true);
});

it('Is a getter.', () => {
expect(typeof Object.getOwnPropertyDescriptor(Element.prototype, 'children')?.get).toBe(
'function'
);
});
});

describe('get id()', () => {
Expand Down
23 changes: 23 additions & 0 deletions packages/happy-dom/test/nodes/node/Node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,29 @@ describe('Node', () => {
});
});

describe('get childNodes()', () => {
it('Returns child nodes.', () => {
const div = document.createElement('div');
const span = document.createElement('span');
const text = document.createTextNode('text');
const comment = document.createComment('comment');

div.appendChild(span);
div.appendChild(text);
div.appendChild(comment);

expect(div.childNodes.length).toBe(3);
expect(div.childNodes[0] === span).toBe(true);
expect(div.childNodes[1] === text).toBe(true);
expect(div.childNodes[2] === comment).toBe(true);
});
it('Is a getter.', () => {
expect(typeof Object.getOwnPropertyDescriptor(Node.prototype, 'childNodes')?.get).toBe(
'function'
);
});
});

describe('get nodeValue()', () => {
it('Returns null.', () => {
expect(new Node().nodeValue).toBe(null);
Expand Down

0 comments on commit 28f9b72

Please sign in to comment.