-
-
Notifications
You must be signed in to change notification settings - Fork 210
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
delete element.dataset.keyname throws TypeError: 'deleteProperty' on proxy #652
Comments
but, this code returns false when the property not exist, so there is a difference in behavior. happy-dom/packages/happy-dom/src/nodes/html-element/HTMLElement.ts Lines 252 to 258 in 67d95f0
|
…rty-delete-when-property-not-exists #652@patch: Fixed deleting not exist dataset properties.
@capricorn86 This issue has been fixed and should be able to be closed. |
@btea This appears to not be fixed as of the latest version (10.11.2). Here's a very simple case that I can reproduce in a Jest test (using the Happy DOM Jest environment): test("is able to delete a non-existent dataset key", () => {
delete document.documentElement.dataset.xyz
}) Fails with:
|
This matches the behavior in the browser.
Add a new method, `_removeNamedItem`, which removes the item without throwing if it does not exist, and override that in subclasses instead of the primary `removeNamedItem` method.
…nonexistent-key #652@patch: Allow deletion of nonexistent keys from dataset
Thank you for reporting @WebMechanic, @takaya1992, @btea and @sasha-evidation! 🙂 Big thanks to @RussianCow for the contribution ⭐ There is a fix out now: |
Describe the bug
To remove an attribute from an element's dataset, you should be able to use the delete operator:
delete element.dataset.keyname
whether.keyname
exists or not.If
.keyname
does not already exist on the dataset, the statement throws with aTypeError: 'deleteProperty' on proxy: trap returned falsish for property 'keyname'
.Native DOM allows to do so and even returns
true
.To Reproduce
inside a Browser with native DOM
inside a unit test with Happy DOM
same but keys are initialised first with "anything"
Expected behavior
To not throw a TypeError when attempting to
delete
a non-existing dataset key, but silently ignore that the key does not exist.Additional context
I'm writing a utility to manage multiple values inside data attributes (data-fubar="foo bar bat baz") similar to
classList
. Between tests I wanted to cleandataset
and ran into this issue.Not a showstopper 'cos I can just used a different key for each suite.
The text was updated successfully, but these errors were encountered: