diff --git a/packages/react-test-renderer/src/ReactShallowRenderer.js b/packages/react-test-renderer/src/ReactShallowRenderer.js index 54f671e6607d0..ceaf1e748afe5 100644 --- a/packages/react-test-renderer/src/ReactShallowRenderer.js +++ b/packages/react-test-renderer/src/ReactShallowRenderer.js @@ -107,7 +107,11 @@ class ReactShallowRenderer { this._mountClassComponent(element, this._context); } else { - this._rendered = element.type(element.props, this._context); + this._rendered = element.type.call( + undefined, + element.props, + this._context, + ); } } diff --git a/packages/react-test-renderer/src/__tests__/ReactShallowRenderer-test.js b/packages/react-test-renderer/src/__tests__/ReactShallowRenderer-test.js index b47495bca9818..15eb862fcf51f 100644 --- a/packages/react-test-renderer/src/__tests__/ReactShallowRenderer-test.js +++ b/packages/react-test-renderer/src/__tests__/ReactShallowRenderer-test.js @@ -1407,4 +1407,15 @@ describe('ReactShallowRenderer', () => { instance.setState(state => ({count: state.count + 1})); expect(log).toEqual(['render']); }); + + it('should not get this in a functional component', () => { + const logs = []; + function Foo() { + logs.push(this); + return
foo
; + } + const shallowRenderer = createRenderer(); + shallowRenderer.render(); + expect(logs).toEqual([undefined]); + }); });