align shallow renderer with other renderers in defaulting state to null on mount (#11965)
jwbay committed
Jan 5, 2018 at 13:44 UTC
39be83565c65f9c522150e52375167568a2a1459
2 files changed
+14
-1
packages/react-test-renderer/src/ReactShallowRenderer.js
+1
-1
@@ -125,7 +125,7 @@ class ReactShallowRenderer {
125
_mountClassComponent(props, context) {
126
this._instance.context = context;
127
this._instance.props = props;
128
- this._instance.state = this._instance.state || emptyObject;
128
+ this._instance.state = this._instance.state || null;
129
this._instance.updater = this._updater;
130
131
if (typeof this._instance.componentWillMount === 'function') {
packages/react-test-renderer/src/__tests__/ReactShallowRenderer-test.js
+13
@@ -947,4 +947,17 @@ describe('ReactShallowRenderer', () => {
947
renderAndVerifyWarningAndError([], 'array');
948
renderAndVerifyWarningAndError({}, 'object');
949
});
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
+ });
963
});