Skip to content

Commit

Permalink
align shallow renderer with other renderers in defaulting state to nu…
Browse files Browse the repository at this point in the history
…ll on mount (#11965)
  • Loading branch information
jwbay authored and gaearon committed Jan 5, 2018
1 parent cd8bc64 commit 63791ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ReactShallowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ReactShallowRenderer {
_mountClassComponent(props, context) {
this._instance.context = context;
this._instance.props = props;
this._instance.state = this._instance.state || emptyObject;
this._instance.state = this._instance.state || null;
this._instance.updater = this._updater;

if (typeof this._instance.componentWillMount === 'function') {
Expand Down
13 changes: 13 additions & 0 deletions src/__tests__/ReactShallowRenderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -947,4 +947,17 @@ describe('ReactShallowRenderer', () => {
renderAndVerifyWarningAndError([], 'array');
renderAndVerifyWarningAndError({}, 'object');
});

it('should have initial state of null if not defined', () => {
class SomeComponent extends React.Component {
render() {
return <span />;
}
}

const shallowRenderer = createRenderer();
shallowRenderer.render(<SomeComponent />);

expect(shallowRenderer.getMountedInstance().state).toBeNull();
});
});

0 comments on commit 63791ae

Please sign in to comment.