Skip to content
Closed
3 changes: 2 additions & 1 deletion src/renderers/dom/shared/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ function assertValidProps(component, props) {
props.style == null || typeof props.style === 'object',
'The `style` prop expects a mapping from style properties to values, ' +
'not a string. For example, style={{marginRight: spacing + \'em\'}} when ' +
'using JSX.'
'using JSX.%s',
getDeclarationErrorAddendum(component)
);
}

Expand Down
49 changes: 43 additions & 6 deletions src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,28 @@ describe('ReactDOMComponent', function() {
expect(function() {
mountComponent({style: 'display: none'});
}).toThrow(
'Invariant Violation: The `style` prop expects a mapping from style ' +
'properties to values, not a string. For example, ' +
'style={{marginRight: spacing + \'em\'}} when using JSX.'
'Invariant Violation: ' +
'The `style` prop expects a mapping from style properties to values, ' +
'not a string. For example, style={{marginRight: spacing + \'em\'}} when ' +
'using JSX.'
);
});

it('should report component containing invalid styles', function() {
var container = document.createElement('div');
var Animal = React.createClass({
render: function() {
return <div style={1}></div>;
},
});

expect(function() {
React.render(<Animal/>, container);
}).toThrow(
'Invariant Violation: ' +
'The `style` prop expects a mapping from style properties to values, not ' +
'a string. For example, style={{marginRight: spacing + \'em\'}} when using JSX. ' +
'This DOM node was rendered by `Animal`.'
);
});

Expand Down Expand Up @@ -718,9 +737,27 @@ describe('ReactDOMComponent', function() {
expect(function() {
React.render(<div style={1}></div>, container);
}).toThrow(
'Invariant Violation: The `style` prop expects a mapping from style ' +
'properties to values, not a string. For example, ' +
'style={{marginRight: spacing + \'em\'}} when using JSX.'
'Invariant Violation: ' +
'The `style` prop expects a mapping from style properties to values, ' +
'not a string. For example, style={{marginRight: spacing + \'em\'}} when ' +
'using JSX.'
);
});

it('should report component containing invalid styles', function() {
var Animal = React.createClass({
render: function() {
return <div style={1}></div>;
},
});

expect(function() {
React.render(<Animal/>, container);
}).toThrow(
'Invariant Violation: ' +
'The `style` prop expects a mapping from style properties to values, ' +
'not a string. For example, style={{marginRight: spacing + \'em\'}} when ' +
'using JSX. This DOM node was rendered by `Animal`.'
);
});

Expand Down