@samitouri / QOS-React-2 / commits / 1de77f1fbe

Ensure className={false} turns into string 'false'

Fixes inconsistency shown by http://jsfiddle.net/zpao/qeXLm/.

Ben Alpert committed Feb 13, 2014 at 18:27 UTC 1de77f1fbe56047998c53999b06b0751001d7807
2 files changed +27 -11
src/browser/dom/DefaultDOMPropertyConfig.js
-11
@@ -186,17 +186,6 @@ var DefaultDOMPropertyConfig = {
186 radioGroup: 'radiogroup',
187 spellCheck: 'spellcheck',
188 srcDoc: 'srcdoc'
189 - },
190 - DOMMutationMethods: {
191 - /**
192 - * Setting `className` to null may cause it to be set to the string "null".
193 - *
194 - * @param {DOMElement} node
195 - * @param {*} value
196 - */
197 - className: function(node, value) {
198 - node.className = value || '';
199 - }
189 }
190 };
191
src/browser/dom/__tests__/DOMPropertyOperations-test.js
+27
@@ -23,6 +23,8 @@ describe('DOMPropertyOperations', function() {
23 var DOMPropertyOperations;
24 var DOMProperty;
25
26 + var mocks;
27 +
28 beforeEach(function() {
29 require('mock-modules').dumpCache();
30 var ReactDefaultInjection = require('ReactDefaultInjection');
@@ -30,6 +32,8 @@ describe('DOMPropertyOperations', function() {
32
33 DOMPropertyOperations = require('DOMPropertyOperations');
34 DOMProperty = require('DOMProperty');
35 +
36 + mocks = require('mocks');
37 });
38
39 describe('createMarkupForProperty', function() {
@@ -150,6 +154,27 @@ describe('DOMPropertyOperations', function() {
154 });
155
156 it('should use mutation method where applicable', function() {
157 + var foobarSetter = mocks.getMockFunction();
158 + // inject foobar DOM property
159 + DOMProperty.injection.injectDOMPropertyConfig({
160 + Properties: {foobar: null},
161 + DOMMutationMethods: {
162 + foobar: foobarSetter
163 + }
164 + });
165 +
166 + DOMPropertyOperations.setValueForProperty(
167 + stubNode,
168 + 'foobar',
169 + 'cows say moo'
170 + );
171 +
172 + expect(foobarSetter.mock.calls.length).toBe(1);
173 + expect(foobarSetter.mock.calls[0][0]).toBe(stubNode);
174 + expect(foobarSetter.mock.calls[0][1]).toBe('cows say moo');
175 + });
176 +
177 + it('should set className to empty string instead of null', function() {
178 DOMPropertyOperations.setValueForProperty(
179 stubNode,
180 'className',
@@ -162,6 +187,8 @@ describe('DOMPropertyOperations', function() {
187 'className',
188 null
189 );
190 + // className should be '', not 'null' or null (which becomes 'null' in
191 + // some browsers)
192 expect(stubNode.className).toBe('');
193 });
194