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

data argument of createTextNode is not coerced into a string #1380

Closed
mcous opened this issue Apr 4, 2024 · 1 comment · Fixed by #1384
Closed

data argument of createTextNode is not coerced into a string #1380

mcous opened this issue Apr 4, 2024 · 1 comment · Fixed by #1384
Labels
bug Something isn't working

Comments

@mcous
Copy link

mcous commented Apr 4, 2024

Describe the bug

Hello! I'm filing this issue in response to an issue that got raised over at testing-library/svelte-testing-library#343.

  • document.createTextNode(data) is used to create text nodes
  • The input data is expected to be a DOMString
  • In browsers I've tested (latest Chromium, Firefox, and Safari), if you pass a non-string to createTextNode, it will be coerced into a string
  • In Happy DOM, the data is not coerced, and node.data ends up not a string, causing problems in downstream consumers

To Reproduce

// index.js
import { Window } from "happy-dom";

const window = new Window({ url: "https://localhost:8080" });
const node = window.document.createTextNode(2);

console.log(node.data, typeof node.data);
> node index.js
2 number

In the case of the issue filed in @testing-library/svelte: svelte@4 erroneously passes a non-string to createTextNode, and then the pretty printing library that is used to print test results chokes because it tries to do a String.replace on node.data, which may not be a string

Expected behavior

I expect the resulting data property of createTextNode to always be a string

Additional context

Tested with happy-dom@14.4.0

@mcous mcous added the bug Something isn't working label Apr 4, 2024
odanado added a commit to odanado/happy-dom that referenced this issue Apr 5, 2024
odanado added a commit to odanado/happy-dom that referenced this issue Apr 5, 2024
@capricorn86
Copy link
Owner

Thank you for reporting @mcous! 🙂

Big thanks to @odanado for contributing with a fix ⭐

You can read more about the release here:
https://github.com/capricorn86/happy-dom/releases/tag/v14.6.1

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

Successfully merging a pull request may close this issue.

2 participants