@samitouri / QOS-React-2 / commits / c3cfcf073d

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.

Ben Alpert committed Feb 26, 2014 at 21:32 UTC c3cfcf073dab2e6fff1ebf32ef2bbacc37a57992
2 files changed +16 -1
src/browser/ui/dom/DOMPropertyOperations.js
+1 -1
@@ -136,7 +136,7 @@ var DOMPropertyOperations = {
136 }
137 } else if (DOMProperty.isCustomAttribute(name)) {
138 if (value == null) {
139 - node.removeAttribute(DOMProperty.getAttributeName[name]);
139 + node.removeAttribute(name);
140 } else {
141 node.setAttribute(name, '' + value);
142 }
src/browser/ui/dom/__tests__/DOMPropertyOperations-test.js
+15
@@ -153,6 +153,21 @@ describe('DOMPropertyOperations', function() {
153 expect(stubNode.hasAttribute('allowFullScreen')).toBe(false);
154 });
155
156 + it('should remove when setting custom attr to null', function() {
157 + DOMPropertyOperations.setValueForProperty(
158 + stubNode,
159 + 'data-foo',
160 + 'bar'
161 + );
162 + expect(stubNode.hasAttribute('data-foo')).toBe(true);
163 + DOMPropertyOperations.setValueForProperty(
164 + stubNode,
165 + 'data-foo',
166 + null
167 + );
168 + expect(stubNode.hasAttribute('data-foo')).toBe(false);
169 + });
170 +
171 it('should use mutation method where applicable', function() {
172 var foobarSetter = mocks.getMockFunction();
173 // inject foobar DOM property