Skip to content

Commit 63791ae

Browse files
jwbaygaearon
authored andcommitted
align shallow renderer with other renderers in defaulting state to null on mount (#11965)
1 parent cd8bc64 commit 63791ae

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/ReactShallowRenderer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class ReactShallowRenderer {
125125
_mountClassComponent(props, context) {
126126
this._instance.context = context;
127127
this._instance.props = props;
128-
this._instance.state = this._instance.state || emptyObject;
128+
this._instance.state = this._instance.state || null;
129129
this._instance.updater = this._updater;
130130

131131
if (typeof this._instance.componentWillMount === 'function') {

src/__tests__/ReactShallowRenderer-test.js

+13
Original file line numberDiff line numberDiff line change
@@ -947,4 +947,17 @@ describe('ReactShallowRenderer', () => {
947947
renderAndVerifyWarningAndError([], 'array');
948948
renderAndVerifyWarningAndError({}, 'object');
949949
});
950+
951+
it('should have initial state of null if not defined', () => {
952+
class SomeComponent extends React.Component {
953+
render() {
954+
return <span />;
955+
}
956+
}
957+
958+
const shallowRenderer = createRenderer();
959+
shallowRenderer.render(<SomeComponent />);
960+
961+
expect(shallowRenderer.getMountedInstance().state).toBeNull();
962+
});
950963
});

0 commit comments

Comments
 (0)