Skip to content

Commit

Permalink
feat: add Node.hasChildNodes support. (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall committed Feb 23, 2023
1 parent ed405b2 commit d0929f7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions bridge/core/dom/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface Node extends EventTarget {
readonly nodeName: string;

nodeValue: string | null;
hasChildNodes(): boolean;

/**
* Returns the children.
Expand Down
1 change: 1 addition & 0 deletions bridge/core/dom/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class Node : public EventTarget {
Node* removeChild(Node* child, ExceptionState&);
Node* appendChild(Node* new_child, ExceptionState&);

bool hasChildNodes(ExceptionState& exception_state) const { return firstChild(); }
bool hasChildren() const { return firstChild(); }
Node* cloneNode(bool deep, ExceptionState&) const;
Node* cloneNode(ExceptionState&) const;
Expand Down
10 changes: 10 additions & 0 deletions integration_tests/specs/dom/nodes/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ describe('Node API', () => {
expect(el.isConnected).toEqual(false);
});

it('Node.hasChildNodes', () => {
let container = document.createElement('div');
expect(container.hasChildNodes()).toBe(false);
let a = document.createElement('div');
container.appendChild(a);
expect(container.hasChildNodes()).toBe(true);
container.removeChild(a);
expect(container.hasChildNodes()).toBe(false);
});

it('nextSibling should to null when child is lastChild of one children list', () => {
let container = document.createElement('div');
let child = document.createElement('div');
Expand Down

0 comments on commit d0929f7

Please sign in to comment.