Remove custom attrs properly when setting to null

I don't think this particular codepath was exercised at all (because all the callers call deleteValueForProperty) but this fixes a bug here nonetheless.
This commit is contained in:
Ben Alpert
2014-02-26 21:32:20 -08:00
parent 1d27770b40
commit c3cfcf073d
2 changed files with 16 additions and 1 deletions
+1 -1
View File
@@ -136,7 +136,7 @@ var DOMPropertyOperations = {
}
} else if (DOMProperty.isCustomAttribute(name)) {
if (value == null) {
node.removeAttribute(DOMProperty.getAttributeName[name]);
node.removeAttribute(name);
} else {
node.setAttribute(name, '' + value);
}
@@ -153,6 +153,21 @@ describe('DOMPropertyOperations', function() {
expect(stubNode.hasAttribute('allowFullScreen')).toBe(false);
});
it('should remove when setting custom attr to null', function() {
DOMPropertyOperations.setValueForProperty(
stubNode,
'data-foo',
'bar'
);
expect(stubNode.hasAttribute('data-foo')).toBe(true);
DOMPropertyOperations.setValueForProperty(
stubNode,
'data-foo',
null
);
expect(stubNode.hasAttribute('data-foo')).toBe(false);
});
it('should use mutation method where applicable', function() {
var foobarSetter = mocks.getMockFunction();
// inject foobar DOM property