capricorn86 / happy-dom

A JavaScript implementation of a web browser without its graphical user interface
MIT License
3.09k stars 185 forks source link

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

Closed mcous closed 3 months ago

mcous commented 3 months ago

Describe the bug

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

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

capricorn86 commented 3 months ago

Thank you for reporting @mcous! :slightly_smiling_face:

Big thanks to @odanado for contributing with a fix :star:

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