diff --git a/scripts/fiber/tests-failing.txt b/scripts/fiber/tests-failing.txt index 36eaf9ae75c..51334e9a255 100644 --- a/scripts/fiber/tests-failing.txt +++ b/scripts/fiber/tests-failing.txt @@ -19,9 +19,6 @@ src/renderers/__tests__/ReactPerf-test.js * should not count time in a portal towards lifecycle method * should work when measurement starts during reconciliation -src/renderers/__tests__/refs-test.js -* Should increase refs with an increase in divs - src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js * gives source code refs for unknown prop warning (ssr) * gives source code refs for unknown prop warning for exact elements (ssr) diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index 072fe059889..38170c348cb 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -841,6 +841,8 @@ src/renderers/__tests__/refs-destruction-test.js * should not error when destroying child with ref asynchronously src/renderers/__tests__/refs-test.js +* Should increase refs with an increase in divs +* Should correctly get the ref * Allow refs to hop around children correctly * always has a value for this.refs * ref called correctly for stateless component when __DEV__ = false diff --git a/src/renderers/__tests__/refs-test.js b/src/renderers/__tests__/refs-test.js index 8cf2c5aa7ab..10b5d54ac8f 100644 --- a/src/renderers/__tests__/refs-test.js +++ b/src/renderers/__tests__/refs-test.js @@ -144,12 +144,23 @@ describe('reactiverefs', () => { // Now reset again ReactTestUtils.Simulate.click(testRefsComponent.refs.resetDiv); expectClickLogsLengthToBe(testRefsComponent, 1); - }); - }); +describe('factory components', () => { + it('Should correctly get the ref', () => { + function Comp() { + return { + render() { + return
; + }, + }; + } + const inst = ReactTestUtils.renderIntoDocument(); + expect(inst.refs.elemRef.tagName).toBe('DIV'); + }); +}); /** * Tests that when a ref hops around children, we can track that correctly. diff --git a/src/renderers/shared/fiber/ReactFiberClassComponent.js b/src/renderers/shared/fiber/ReactFiberClassComponent.js index 87f3426099e..cd47bd488c3 100644 --- a/src/renderers/shared/fiber/ReactFiberClassComponent.js +++ b/src/renderers/shared/fiber/ReactFiberClassComponent.js @@ -291,6 +291,7 @@ module.exports = function( instance.props = props; instance.state = state; + instance.refs = emptyObject; instance.context = getMaskedContext(workInProgress, unmaskedContext); if (typeof instance.componentWillMount === 'function') {