diff --git a/packages/happy-dom/src/nodes/document/Document.ts b/packages/happy-dom/src/nodes/document/Document.ts index 43235f9ac..e3fcd72dd 100644 --- a/packages/happy-dom/src/nodes/document/Document.ts +++ b/packages/happy-dom/src/nodes/document/Document.ts @@ -281,6 +281,24 @@ export default class Document extends Node implements IDocument { return this.defaultView.location.href; } + /** + * Returns URL. + * + * @returns the URL of the current document. + * */ + public get URL(): string { + return this.defaultView.location.href; + } + + /** + * Returns document URI. + * + * @returns the URL of the current document. + * */ + public get documentURI(): string { + return this.URL; + } + /** * Inserts a set of Node objects or DOMString objects after the last child of the ParentNode. DOMString objects are inserted as equivalent Text nodes. * diff --git a/packages/happy-dom/src/nodes/document/IDocument.ts b/packages/happy-dom/src/nodes/document/IDocument.ts index a1967ec27..7ce365831 100644 --- a/packages/happy-dom/src/nodes/document/IDocument.ts +++ b/packages/happy-dom/src/nodes/document/IDocument.ts @@ -39,6 +39,8 @@ export default interface IDocument extends IParentNode { readonly readyState: DocumentReadyStateEnum; readonly charset: string; readonly characterSet: string; + readonly URL: string; + readonly documentURI: string; cookie: string; /** diff --git a/packages/happy-dom/test/nodes/document/Document.test.ts b/packages/happy-dom/test/nodes/document/Document.test.ts index 5a349c028..551c07ac9 100644 --- a/packages/happy-dom/test/nodes/document/Document.test.ts +++ b/packages/happy-dom/test/nodes/document/Document.test.ts @@ -398,6 +398,19 @@ describe('Document', () => { }); }); + describe('URL', () => { + it('Returns the URL of the document.', () => { + document.location.href = 'http://localhost:8080/path/to/file.html'; + expect(document.URL).toBe('http://localhost:8080/path/to/file.html'); + }); + }); + describe('documentURI', () => { + it('Returns the documentURI of the document.', () => { + document.location.href = 'http://localhost:8080/path/to/file.html'; + expect(document.documentURI).toBe('http://localhost:8080/path/to/file.html'); + }); + }); + describe('append()', () => { it('Inserts a set of Node objects or DOMString objects after the last child of the ParentNode. DOMString objects are inserted as equivalent Text nodes.', () => { const node1 = document.createComment('test1');