Skip to content

Commit

Permalink
capricorn86#526@minor: Adds support for Document.documentURI and Docu…
Browse files Browse the repository at this point in the history
…ment.URL.
  • Loading branch information
Mas0nShi committed Jul 1, 2022
1 parent 9f9df58 commit a71819f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/happy-dom/src/nodes/document/Document.ts
Expand Up @@ -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.
*
Expand Down
2 changes: 2 additions & 0 deletions packages/happy-dom/src/nodes/document/IDocument.ts
Expand Up @@ -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;

/**
Expand Down
13 changes: 13 additions & 0 deletions packages/happy-dom/test/nodes/document/Document.test.ts
Expand Up @@ -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');
Expand Down

0 comments on commit a71819f

Please sign in to comment.