Skip to content

Commit

Permalink
capricorn86#652@patch: Allow deletion of nonexistent keys from dataset
Browse files Browse the repository at this point in the history
This matches the behavior in the browser.
  • Loading branch information
RussianCow committed Aug 30, 2023
1 parent 61dd11d commit 974d17a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/happy-dom/src/nodes/element/Dataset.ts
Expand Up @@ -46,10 +46,10 @@ export default class Dataset {
return true;
},
deleteProperty(dataset: DatasetRecord, key: string): boolean {
return (
!!element.attributes.removeNamedItem('data-' + Dataset.camelCaseToKebab(key)) &&
delete dataset[key]
);
if (element.attributes.removeNamedItem('data-' + Dataset.camelCaseToKebab(key))) {
return delete dataset[key];
}
return true;
},
ownKeys(dataset: DatasetRecord): string[] {
// According to Mozilla we have to update the dataset object (target) to contain the same keys as what we return:
Expand Down
Expand Up @@ -300,6 +300,8 @@ describe('HTMLElement', () => {
expect(element.getAttribute('data-test-delta')).toBe(null);
expect(Object.keys(dataset)).toEqual(['testAlpha', 'testBeta', 'testGamma']);
expect(Object.values(dataset)).toEqual(['value2', 'value4', 'value5']);

delete dataset.nonExistentKey;
});

// https://github.com/capricorn86/happy-dom/issues/493
Expand Down

0 comments on commit 974d17a

Please sign in to comment.