Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions docs/api/ReactWrapper/ref.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `.ref(refName) => ReactWrapper`
# `.ref(refName) => ReactComponent | HTMLElement`

Returns a wrapper of the node that matches the provided reference name.
Returns the node that matches the provided reference name.


NOTE: can only be called on a wrapper instance that is also the root instance.
Expand All @@ -12,7 +12,7 @@ NOTE: can only be called on a wrapper instance that is also the root instance.

#### Returns

`ReactWrapper`: A wrapper of the node that matches the provided reference name.
`ReactComponent | HTMLElement`: The node that matches the provided reference name. This can be a react component instance, or an HTML element instance.



Expand All @@ -35,8 +35,7 @@ class Foo extends React.Component {

```jsx
const wrapper = mount(<Foo />);
expect(wrapper.ref('secondRef').prop('amount')).to.equal(4);
expect(wrapper.ref('secondRef').text()).to.equal('Second');
expect(wrapper.ref('secondRef').innerText).to.equal('Second');
```


Expand Down
6 changes: 3 additions & 3 deletions packages/enzyme/src/ReactWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ class ReactWrapper {
}

/**
* If the root component contained a ref, you can access it here
* and get a wrapper around it.
* If the root component contained a ref, you can access it here and get the relevant
* react component instance or HTML element instance.
*
* NOTE: can only be called on a wrapper instance that is also the root instance.
*
* @param {String} refname
* @returns {ReactWrapper}
* @returns {ReactComponent | HTMLElement}
*/
ref(refname) {
if (this[ROOT] !== this) {
Expand Down