capricorn86 / happy-dom

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

testing-library-react prints incorrect html for form when using screen.debug() #1619

Open gkiely opened 1 day ago

gkiely commented 1 day ago

Describe the bug When using screen.debug with the following code

import { render, screen } from '@testing-library/react';
import { test } from 'vitest';
test('render', () => {
  render(<form>
    <div>test</div>
    <input type="text" />
    <button>submit</button>
  </form>);
  screen.debug();
})

happy-dom

bound HTMLFormElement {
  "0": <input
    type="text"
  />,
  "1": <button>
    submit
  </button>,
}

jsdom

<form>
  <div>
    test
  </div>
  <input
    type="text"
  />
  <button>
    submit
  </button>
</form>

To Reproduce

1. git clone https://github.com/gkiely/vite-project
3. npm i
4. npm test # output for jsdom
5. Update package.json: "test": "vitest --environment happy-dom"
6. npm test # output for happy-dom

Expected behavior Should output all html in form

gkiely commented 1 day ago

happy to open an issue with react-testing-library, just wanted to check here first 😄

gkiely commented 1 day ago

Relevant code: https://github.com/testing-library/react-testing-library/blob/3dcd8a9649e25054c0e650d95fca2317b7008576/src/pure.js#L162

https://github.com/testing-library/dom-testing-library/blob/a86c54ccda5242ad8dfc1c70d31980bdbf96af7f/src/pretty-dom.js#L48