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

Checkboxes are missing checked attribute when serialized #1587

Open
Tsubasa1218 opened this issue Nov 6, 2024 · 1 comment
Open

Checkboxes are missing checked attribute when serialized #1587

Tsubasa1218 opened this issue Nov 6, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Tsubasa1218
Copy link

Describe the bug
I want to bring up #1023 again, as the original behaviour described was not the one implemented in the fix.

When a Input element with type Checkbox is serialized in React tests, the checked="" is not being added.

To Reproduce

I've created this repo that showcases the issue: https://github.com/Tsubasa1218/happy-dom-checkbox.

The app only renders an Input[type="checkbox"] with checked={true}. I then create a snapshot test for both Happy DOM and JSDOM. You can check the snapshots here: https://github.com/Tsubasa1218/happy-dom-checkbox/tree/main/src/__snapshots__

Basically, the JSDOM output has checked="" but the Happy DOM doesn't.

I have tested that the checkbox is actually checked.

Expected behavior
Serialized output for checkboxes includes checked="" when the checkbox is checked.

Screenshots
This is the Happy DOM result

image

And this is the JSDOM result

image

Device:

  • OS: MacOS 15.1
  • Browser: Vitest
  • Version: 2.1.4
  • Happy DOM version: 15.10.1
  • JSDOM version: 25.0.1

Additional context

I've been debugging the serialization step in our app, and I can see that the checkbox does not have the checked property in the namedItems map. This in XMLSerializer.js

image

This is the real test; Not much different from the repo I provided.

image

I haven't been able to find the place where these properties are being added.

Thanks for the help. If there is anything I can help with, let me know :)

@Tsubasa1218 Tsubasa1218 added the bug Something isn't working label Nov 6, 2024
@Tsubasa1218
Copy link
Author

Looking at it more, it looks like the problem is when React DOM creates the node, resulting in the Input Node having the attributes I shared above.

I don't really know where the elements are being created, so any help would be appreciated (or a fix...)

Thanks again!

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

1 participant