Repository: enzymejs/enzyme (JavaScript)

Issue:
refs are not triggered on root elements
Refs on the mounted root element do not appear to be triggered. Is this expected behaviour?

```
  it('triggers refs on child elements', (done) => {
    mount(<div><span ref={(c) => done()}/></div>);
  });

  it('triggers refs on root elements', (done) => {
    mount(<span ref={(c) => done()}/>);
  });
```

### Current behavior

The child elements test passes, but the root element test fails

### Expected behavior

Both tests should pass

#### API

- [ ] shallow
- [x] mount
- [ ] render

#### Version

| library         | version
| ---------------- | -------
| Enzyme           |  3.3.0
| React            |  16.2.0

#### Adapter

- [x] enzyme-adapter-react-16
- [ ] enzyme-adapter-react-15
- [ ] enzyme-adapter-react-15.4
- [ ] enzyme-adapter-react-14
- [ ] enzyme-adapter-react-13
- [ ] enzyme-adapter-react-helper
- [ ] others ( ) 



Discussion:
Does this happen with other versions of react as well?
I was able to reproduce this in React 16.0.0 and 15.0.0



Patch:
diff --git a/packages/enzyme-adapter-react-13/src/ReactThirteenAdapter.js b/packages/enzyme-adapter-react-13/src/ReactThirteenAdapter.js
index 860204dcc..37edd3520 100644
--- a/packages/enzyme-adapter-react-13/src/ReactThirteenAdapter.js
+++ b/packages/enzyme-adapter-react-13/src/ReactThirteenAdapter.js
@@ -111,12 +111,15 @@ class ReactThirteenAdapter extends EnzymeAdapter {
     return {
       render(el, context, callback) {
         if (instance === null) {
-          const ReactWrapperComponent = createMountWrapper(el, options);
-          const wrappedEl = React.createElement(ReactWrapperComponent, {
-            Component: el.type,
-            props: el.props,
+          const { ref, type, props } = el;
+          const wrapperProps = {
+            Component: type,
+            props,
             context,
-          });
+            ...(ref && { ref }),
+          };
+          const ReactWrapperComponent = createMountWrapper(el, options);
+          const wrappedEl = React.createElement(ReactWrapperComponent, wrapperProps);
           instance = React.render(wrappedEl, domNode);
           if (typeof callback === 'function') {
             callback();
diff --git a/packages/enzyme-adapter-react-14/src/ReactFourteenAdapter.js b/packages/enzyme-adapter-react-14/src/ReactFourteenAdapter.js
index 8658cc983..0d89c9181 100644
--- a/packages/enzyme-adapter-react-14/src/ReactFourteenAdapter.js
+++ b/packages/enzyme-adapter-react-14/src/ReactFourteenAdapter.js
@@ -83,12 +83,15 @@ class ReactFifteenAdapter extends EnzymeAdapter {
     return {
       render(el, context, callback) {
         if (instance === null) {
-          const ReactWrapperComponent = createMountWrapper(el, options);
-          const wrappedEl = React.createElement(ReactWrapperComponent, {
-            Component: el.type,
-            props: el.props,
+          const { type, props, ref } = el;
+          const wrapperProps = {
+            Component: type,
+            props,
             context,
-          });
+            ...(ref && { ref }),
+          };
+          const ReactWrapperComponent = createMountWrapper(el, options);
+          const wrappedEl = React.createElement(ReactWrapperComponent, wrapperProps);
           instance = ReactDOM.render(wrappedEl, domNode);
           if (typeof callback === 'function') {
             callback();
diff --git a/packages/enzyme-adapter-react-15.4/src/ReactFifteenFourAdapter.js b/packages/enzyme-adapter-react-15.4/src/ReactFifteenFourAdapter.js
index 2ec079e8f..e55314949 100644
--- a/packages/enzyme-adapter-react-15.4/src/ReactFifteenFourAdapter.js
+++ b/packages/enzyme-adapter-react-15.4/src/ReactFifteenFourAdapter.js
@@ -114,12 +114,15 @@ class ReactFifteenFourAdapter extends EnzymeAdapter {
     return {
       render(el, context, callback) {
         if (instance === null) {
-          const ReactWrapperComponent = createMountWrapper(el, options);
-          const wrappedEl = React.createElement(ReactWrapperComponent, {
-            Component: el.type,
-            props: el.props,
+          const { type, props, ref } = el;
+          const wrapperProps = {
+            Component: type,
+            props,
             context,
-          });
+            ...(ref && { ref }),
+          };
+          const ReactWrapperComponent = createMountWrapper(el, options);
+          const wrappedEl = React.createElement(ReactWrapperComponent, wrapperProps);
           instance = ReactDOM.render(wrappedEl, domNode);
           if (typeof callback === 'function') {
             callback();
diff --git a/packages/enzyme-adapter-react-15/src/ReactFifteenAdapter.js b/packages/enzyme-adapter-react-15/src/ReactFifteenAdapter.js
index 411fa4e6f..02cdc157c 100644
--- a/packages/enzyme-adapter-react-15/src/ReactFifteenAdapter.js
+++ b/packages/enzyme-adapter-react-15/src/ReactFifteenAdapter.js
@@ -114,12 +114,15 @@ class ReactFifteenAdapter extends EnzymeAdapter {
     return {
       render(el, context, callback) {
         if (instance === null) {
-          const ReactWrapperComponent = createMountWrapper(el, options);
-          const wrappedEl = React.createElement(ReactWrapperComponent, {
-            Component: el.type,
-            props: el.props,
+          const { type, props, ref } = el;
+          const wrapperProps = {
+            Component: type,
+            props,
             context,
-          });
+            ...(ref && { ref }),
+          };
+          const ReactWrapperComponent = createMountWrapper(el, options);
+          const wrappedEl = React.createElement(ReactWrapperComponent, wrapperProps);
           instance = ReactDOM.render(wrappedEl, domNode);
           if (typeof callback === 'function') {
             callback();
diff --git a/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js b/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js
index bcc1f48aa..12fa79ca1 100644
--- a/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js
+++ b/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js
@@ -171,12 +171,15 @@ class ReactSixteenAdapter extends EnzymeAdapter {
     return {
       render(el, context, callback) {
         if (instance === null) {
-          const ReactWrapperComponent = createMountWrapper(el, options);
-          const wrappedEl = React.createElement(ReactWrapperComponent, {
-            Component: el.type,
-            props: el.props,
+          const { type, props, ref } = el;
+          const wrapperProps = {
+            Component: type,
+            props,
             context,
-          });
+            ...(ref && { ref }),
+          };
+          const ReactWrapperComponent = createMountWrapper(el, options);
+          const wrappedEl = React.createElement(ReactWrapperComponent, wrapperProps);
           instance = ReactDOM.render(wrappedEl, domNode);
           if (typeof callback === 'function') {
             callback();


Test patch:
diff --git a/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx b/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
index cc48122ac..971aa5a41 100644
--- a/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
+++ b/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
@@ -56,6 +56,12 @@ describeWithDOM('mount', () => {
       expect(wrapper.children().instance()).to.be.instanceOf(Box);
       expect(wrapper.children().props().bam).to.equal(true);
     });
+
+    it('should call ref', () => {
+      const spy = sinon.spy();
+      mount(<div ref={spy} />);
+      expect(spy).to.have.property('callCount', 1);
+    });
   });
 
   describe('context', () => {