Skip to content

Commit

Permalink
#890@patch: Fixes a issue where "HTMLAnchorElement.toString" returns …
Browse files Browse the repository at this point in the history
…outerHTML instead of the url.
  • Loading branch information
René Schleusner committed May 3, 2023
1 parent 02d731d commit 18b2bb4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,13 @@ export default class HTMLAnchorElement extends HTMLElement implements IHTMLAncho
this.setAttribute('type', type);
}

/**
* @override
*/
public override toString(): string {
return this.href;
}

/**
* @override
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,37 @@ describe('HTMLAnchorElement', () => {
});
});

describe('toString()', () => {
it('Returns the "href" attribute.', () => {
const element = <IHTMLAnchorElement>document.createElement('a');
element.setAttribute('href', 'test');
expect(element.toString()).toBe('https://www.somesite.com/test');
});

it('Returns the "href" attribute when scheme is http.', () => {
const element = <IHTMLAnchorElement>document.createElement('a');
element.setAttribute('href', 'http://www.example.com');
expect(element.toString()).toBe('http://www.example.com/');
});

it('Returns the "href" attribute when scheme is tel.', () => {
const element = <IHTMLAnchorElement>document.createElement('a');
element.setAttribute('href', 'tel:+123456789');
expect(element.toString()).toBe('tel:+123456789');
});

it('Returns the "href" attribute when scheme-relative', () => {
const element = <IHTMLAnchorElement>document.createElement('a');
element.setAttribute('href', '//example.com');
expect(element.toString()).toBe('https://example.com/');
});

it('Returns empty string if "href" attribute is empty.', () => {
const element = <IHTMLAnchorElement>document.createElement('a');
expect(element.toString()).toBe('');
});
});

describe('set href()', () => {
it('Sets the attribute "href".', () => {
const element = <IHTMLAnchorElement>document.createElement('a');
Expand Down

0 comments on commit 18b2bb4

Please sign in to comment.