Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTMLAnchorElement.toString() should return href instead of outerHTML #890

Closed
Schleuse opened this issue May 3, 2023 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@Schleuse
Copy link
Contributor

Schleuse commented May 3, 2023

Describe the bug
HTMLAnchorElement has a specific implementation of toString() that differs from Element.
Element.toString() returns outerHTML where HTMLAnchorElement.toString() should return href.

HTMLAnchorElement.toString()

To Reproduce
Steps to reproduce the behavior:

import { Window } from 'happy-dom';

const window = new Window();
const document = window.document;
const anchor = document.createElement('a');
anchor.setAttribute('href', 'https://github.com/capricorn86/happy-dom');
anchor.innerHTML = 'Happy DOM';

console.log({
  toString: anchor.toString(),
  href: anchor.href
});

/* prints:
{
  toString: '<a href="https://github.com/capricorn86/happy-dom">Happy DOM</a>',
  href: 'https://github.com/capricorn86/happy-dom'
}
*/

/* should be :
{
  toString: 'https://github.com/capricorn86/happy-dom',
  href: 'https://github.com/capricorn86/happy-dom'
}
*/

Expected behavior
toString() should return the same value as the href property

@Schleuse Schleuse added the bug Something isn't working label May 3, 2023
Schleuse pushed a commit to Schleuse/happy-dom that referenced this issue May 3, 2023
Schleuse pushed a commit to Schleuse/happy-dom that referenced this issue May 3, 2023
…" returns outerHTML instead of the url.

# Bitte geben Sie eine Commit-Beschreibung für Ihre Änderungen ein. Zeilen, die
# mit '#' beginnen, werden beibehalten; wenn Sie möchten, können Sie diese entfernen.
# Eine leere Beschreibung bricht den Commit ab.
#
# Datum:            Wed May 3 14:53:54 2023 +0200
#
# Auf Branch task/890-fix-htmlanchorelement-tostring
# Ihr Branch ist auf demselben Stand wie 'fork/task/890-fix-htmlanchorelement-tostring'.
#
# Zum Commit vorgemerkte Änderungen:
#	geändert:       packages/happy-dom/src/nodes/html-anchor-element/HTMLAnchorElement.ts
#	geändert:       packages/happy-dom/test/nodes/html-anchor-element/HTMLAnchorElement.test.ts
#
Schleuse pushed a commit to Schleuse/happy-dom that referenced this issue May 3, 2023
Schleuse pushed a commit to Schleuse/happy-dom that referenced this issue May 3, 2023
capricorn86 added a commit that referenced this issue May 3, 2023
…tostring

#890@patch: Fixes a issue where "HTMLAnchorElement.toString" returns outerHTML instead of the url
@capricorn86
Copy link
Owner

@Schleuse your fix has been released 🙂

Read more about the release here:
https://github.com/capricorn86/happy-dom/releases/tag/v9.10.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants