Skip to content

Commit

Permalink
Merge pull request #1111 from capricorn86/task/1109-scrollwidth-is-un…
Browse files Browse the repository at this point in the history
…defined-in-documentdocumentelement

#1109@minor: Adds support for Element.scrollWidth.
  • Loading branch information
capricorn86 authored Oct 3, 2023
2 parents bce679e + 11cd910 commit 410beb0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/happy-dom/src/nodes/element/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default class Element extends Node implements IElement {
public prefix: string = null;

public scrollHeight = 0;
public scrollWidth = 0;
public scrollTop = 0;
public scrollLeft = 0;
public readonly namespaceURI: string = null;
Expand Down Expand Up @@ -380,6 +381,7 @@ export default class Element extends Node implements IElement {
(<string>clone.tagName) = this.tagName;
clone.scrollLeft = this.scrollLeft;
clone.scrollTop = this.scrollTop;
clone.scrollWidth = this.scrollWidth;
clone.scrollHeight = this.scrollHeight;
(<string>clone.namespaceURI) = this.namespaceURI;

Expand Down
1 change: 1 addition & 0 deletions packages/happy-dom/src/nodes/element/IElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default interface IElement extends IChildNode, INonDocumentTypeChildNode,
prefix: string | null;
scrollTop: number;
scrollLeft: number;
scrollWidth: number;
scrollHeight: number;
id: string;
className: string;
Expand Down
8 changes: 7 additions & 1 deletion packages/happy-dom/test/nodes/element/Element.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1519,12 +1519,18 @@ describe('Element', () => {
});
}

describe('scrollHeight', () => {
describe('get scrollHeight()', () => {
it('Returns the scroll height.', () => {
expect(element.scrollHeight).toBe(0);
});
});

describe('get scrollWidth()', () => {
it('Returns the scroll width.', () => {
expect(element.scrollWidth).toBe(0);
});
});

describe('toString()', () => {
it('Returns the same as outerHTML.', () => {
expect(element.toString()).toBe(element.outerHTML);
Expand Down

0 comments on commit 410beb0

Please sign in to comment.