Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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)
jwbay authored and yenshih committed Jan 6, 2018
1 parent c6d6f6b commit c6f762e
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
@@ -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') {
Original file line number Diff line number Diff line change
@@ -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.