align shallow renderer with other renderers in defaulting state to null on mount (#11965)
This commit is contained in:
parent
808f31af5c
commit
39be83565c
|
@ -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') {
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue