Don't warn when style value is '0'

This commit is contained in:
Paul O’Shannessy
2016-05-02 11:39:56 -07:00
parent be78a41892
commit fa89cf53f2
2 changed files with 15 additions and 1 deletions
@@ -190,6 +190,18 @@ describe('ReactDOMComponent', function() {
expect(console.error.calls.length).toBe(2);
});
it('should not warn for "0" as a unitless style value', function() {
spyOn(console, 'error');
var Component = React.createClass({
render: function() {
return <div style={{margin: '0'}} />;
},
});
ReactTestUtils.renderIntoDocument(<Component />);
expect(console.error.calls.length).toBe(0);
});
it('should warn nicely about NaN in style', function() {
spyOn(console, 'error');
@@ -51,7 +51,9 @@ function dangerousStyleValue(name, value, component) {
if (typeof value === 'string') {
if (__DEV__) {
if (component) {
// Allow '0' to pass through without warning. 0 is already special and
// doesn't require units, so we don't need to warn about it.
if (component && value !== '0') {
var owner = component._currentElement._owner;
var ownerName = owner ? owner.getName() : null;
if (ownerName && !styleWarnings[ownerName]) {