Skip to content

Commit bdc7ce9

Browse files
committed
Merge pull request facebook#4482 from niole/issue4168
Add additional contextual information to invalid-style-prop warning
2 parents 8b96705 + 70c07c6 commit bdc7ce9

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/renderers/dom/shared/ReactDOMComponent.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ function assertValidProps(component, props) {
261261
props.style == null || typeof props.style === 'object',
262262
'The `style` prop expects a mapping from style properties to values, ' +
263263
'not a string. For example, style={{marginRight: spacing + \'em\'}} when ' +
264-
'using JSX.'
264+
'using JSX.%s',
265+
getDeclarationErrorAddendum(component)
265266
);
266267
}
267268

src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,23 @@ describe('ReactDOMComponent', function() {
721721
);
722722
});
723723

724+
it('should report component containing invalid styles', function() {
725+
var Animal = React.createClass({
726+
render: function() {
727+
return <div style={1}></div>;
728+
},
729+
});
730+
731+
expect(function() {
732+
React.render(<Animal/>, container);
733+
}).toThrow(
734+
'Invariant Violation: The `style` prop expects a mapping from style ' +
735+
'properties to values, not a string. For example, ' +
736+
'style={{marginRight: spacing + \'em\'}} when using JSX. ' +
737+
'This DOM node was rendered by `Animal`.'
738+
);
739+
});
740+
724741
it('should properly escape text content and attributes values', function() {
725742
expect(
726743
ReactDOMServer.renderToStaticMarkup(

0 commit comments

Comments
 (0)