Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /html/dom/elements/global-attributes/dataset-delete.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html>
<head>
<title>Dataset - Delete</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Dataset - Delete</h1>
<div id="log"></div>
<script>
function testDelete(attr, prop)
{
var d = document.createElement("div");
d.setAttribute(attr, "value");
delete d.dataset[prop];
return d.hasAttribute(attr) === false && d.getAttribute(attr) != "value";
}
function testDeleteNoAdd(prop)
{
var d = document.createElement("div");
delete d.dataset[prop];
return true;
}
test(function() { assert_true(testDelete('data-foo', 'foo')); },
"Deleting element.dataset['foo'] should also remove an attribute with name 'data-foo' should it exist.");
test(function() { assert_true(testDelete('data-foo-bar', 'fooBar')); },
"Deleting element.dataset['fooBar'] should also remove an attribute with name 'data-foo-bar' should it exist.");
test(function() { assert_true(testDelete('data--', '-')); },
"Deleting element.dataset['-'] should also remove an attribute with name 'data--' should it exist.");
test(function() { assert_true(testDelete('data--foo', 'Foo')); },
"Deleting element.dataset['Foo'] should also remove an attribute with name 'data--foo' should it exist.");
test(function() {
var d = document.createElement("div");
d.setAttribute('data--foo', "value");
assert_equals(d.dataset['-foo'], undefined);
assert_false('-foo' in d.dataset);
delete d.dataset['-foo'];
assert_true(d.hasAttribute('data--foo'));
assert_equals(d.getAttribute('data--foo'), "value");
}, "Deleting element.dataset['-foo'] should not remove an attribute with name 'data--foo' should it exist.");
test(function() { assert_true(testDelete('data---foo', '-Foo')); },
"Deleting element.dataset['-Foo'] should also remove an attribute with name 'data---foo' should it exist.");
test(function() { assert_true(testDelete('data-', '')); },
"Deleting element.dataset[''] should also remove an attribute with name 'data-' should it exist.");
test(function() { assert_true(testDelete('data-\xE0', '\xE0')); },
"Deleting element.dataset['\xE0'] should also remove an attribute with name 'data-\xE0' should it exist.");
test(function() { assert_true(testDeleteNoAdd('foo')); },
"Deleting element.dataset['foo'] should not throw if even if the element does now have an attribute with the name data-foo.");
</script>
</body>
</html>