Skip to content

Commit

Permalink
skip null ref warning for ReactTestRenderer
Browse files Browse the repository at this point in the history
Only instances created with ReactTestRenderer have a toJSON method
  • Loading branch information
Brandon Dail authored and Brandon Dail committed Sep 5, 2016
1 parent 6a525fd commit b89824f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ var ReactCompositeComponent = {
if (__DEV__) {
var componentName = component && component.getName ?
component.getName() : 'a component';
warning(publicComponentInstance != null,
warning(publicComponentInstance != null || component.toJSON,
'Stateless function components cannot be given refs ' +
'(See ref "%s" in %s created by %s). ' +
'Attempts to access this ref will fail.',
Expand Down
11 changes: 11 additions & 0 deletions src/renderers/testing/__tests__/ReactTestRenderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ describe('ReactTestRenderer', function() {
expect(log).toEqual([null]);
});

it('does not warn with legacy refs', function() {
spyOn(console, 'error');
class Foo extends React.Component {
render() {
return <div ref="foo" />
}
}
ReactTestRenderer.create(<Foo />);
expect(console.error.calls.count()).toBe(0);
});

it('supports error boundaries', function() {
var log = [];
class Angry extends React.Component {
Expand Down

0 comments on commit b89824f

Please sign in to comment.