Merge pull request #4482 from niole/issue4168

Add additional contextual information to invalid-style-prop warning
This commit is contained in:
Paul O’Shannessy
2015-08-27 18:13:29 -07:00
2 changed files with 19 additions and 1 deletions
@@ -261,7 +261,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)
);
}
@@ -721,6 +721,23 @@ describe('ReactDOMComponent', function() {
);
});
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`.'
);
});
it('should properly escape text content and attributes values', function() {
expect(
ReactDOMServer.renderToStaticMarkup(