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

Dataset value is returned as undefined when it is set to empty string #1689

Open
pdanpdan opened this issue Jan 16, 2025 · 1 comment
Open
Labels
bug Something isn't working

Comments

@pdanpdan
Copy link

Describe the bug
Happy-Dom evaluates a dataset key as undefined when it is set to an empty string.
The browser evaluates it correctly to empty string.

To Reproduce
Steps to reproduce the behavior:

  1. document.body.dataset.test = ''
  2. console.log(document.body.dataset.test)
  3. It will output undefined while it should output ''

Expected behavior
It should be evaluated to empty string.

Additional context
It is a regression introduced in v16.0.0 - latest working version is v15.11.7.

@pdanpdan pdanpdan added the bug Something isn't working label Jan 16, 2025
@pdanpdan
Copy link
Author

pdanpdan commented Jan 16, 2025

A relevant regression test would be

element.setAttribute('data-test-empty', '');
const dataset = element.dataset;
expect(dataset.testEmpty).toBe('');
expect(dataset.nonExistentKey).toBeUndefined();
dataset.testEmptyAlso = '';
expect(dataset.testEmptyAlso).toBe('');

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