Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/browser/dom/DefaultDOMPropertyConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,6 @@ var DefaultDOMPropertyConfig = {
radioGroup: 'radiogroup',
spellCheck: 'spellcheck',
srcDoc: 'srcdoc'
},
DOMMutationMethods: {
/**
* Setting `className` to null may cause it to be set to the string "null".
*
* @param {DOMElement} node
* @param {*} value
*/
className: function(node, value) {
node.className = value || '';
}
}
};

Expand Down
27 changes: 27 additions & 0 deletions src/browser/dom/__tests__/DOMPropertyOperations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ describe('DOMPropertyOperations', function() {
var DOMPropertyOperations;
var DOMProperty;

var mocks;

beforeEach(function() {
require('mock-modules').dumpCache();
var ReactDefaultInjection = require('ReactDefaultInjection');
ReactDefaultInjection.inject();

DOMPropertyOperations = require('DOMPropertyOperations');
DOMProperty = require('DOMProperty');

mocks = require('mocks');
});

describe('createMarkupForProperty', function() {
Expand Down Expand Up @@ -150,6 +154,27 @@ describe('DOMPropertyOperations', function() {
});

it('should use mutation method where applicable', function() {
var foobarSetter = mocks.getMockFunction();
// inject foobar DOM property
DOMProperty.injection.injectDOMPropertyConfig({
Properties: {foobar: null},
DOMMutationMethods: {
foobar: foobarSetter
}
});

DOMPropertyOperations.setValueForProperty(
stubNode,
'foobar',
'cows say moo'
);

expect(foobarSetter.mock.calls.length).toBe(1);
expect(foobarSetter.mock.calls[0][0]).toBe(stubNode);
expect(foobarSetter.mock.calls[0][1]).toBe('cows say moo');
});

it('should set className to empty string instead of null', function() {
DOMPropertyOperations.setValueForProperty(
stubNode,
'className',
Expand All @@ -162,6 +187,8 @@ describe('DOMPropertyOperations', function() {
'className',
null
);
// className should be '', not 'null' or null (which becomes 'null' in
// some browsers)
expect(stubNode.className).toBe('');
});

Expand Down