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 (facebook#11965)
  • Loading branch information
jwbay authored and yenshih committed Jan 6, 2018
1 parent c6d6f6b commit c6f762e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/react-test-renderer/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
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 c6f762e

Please sign in to comment.