Skip to content

Commit c2334e6

Browse files
authored
Merge pull request #1261 from juandiegombr/master
#1260@minor: Implement document.forms getter
2 parents aa16292 + 6d2c608 commit c2334e6

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

packages/happy-dom/src/nodes/document/Document.ts

+7
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,13 @@ export default class Document extends Node implements IDocument {
315315
return <IHTMLCollection<IHTMLElement>>this.querySelectorAll('a[href],area[href]');
316316
}
317317

318+
/**
319+
* Returns a collection of all form elements in a document.
320+
*/
321+
public get forms(): IHTMLCollection<IHTMLElement> {
322+
return <IHTMLCollection<IHTMLElement>>this.querySelectorAll('form');
323+
}
324+
318325
/**
319326
* Last element child.
320327
*

packages/happy-dom/src/nodes/document/IDocument.ts

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export default interface IDocument extends IParentNode {
4848
readonly visibilityState: VisibilityStateEnum;
4949
readonly hidden: boolean;
5050
readonly links: IHTMLCollection<IHTMLElement>;
51+
readonly forms: IHTMLCollection<IHTMLElement>;
5152
readonly referrer: string;
5253
readonly currentScript: IHTMLScriptElement;
5354
adoptedStyleSheets: CSSStyleSheet[];

packages/happy-dom/test/nodes/document/Document.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,22 @@ describe('Document', () => {
119119
});
120120
});
121121

122+
describe('get forms()', () => {
123+
it('Returns a elements.', () => {
124+
const form1 = document.createElement('form');
125+
const form2 = document.createElement('form');
126+
127+
document.body.appendChild(form1);
128+
document.body.appendChild(form2);
129+
130+
const forms = document.forms;
131+
132+
expect(forms.length).toBe(2);
133+
expect(forms[0]).toBe(form1);
134+
expect(forms[1]).toBe(form2);
135+
});
136+
});
137+
122138
describe('get scripts()', () => {
123139
it('Returns script elements.', () => {
124140
const div = document.createElement('div');

0 commit comments

Comments
 (0)