enzymejs/enzyme
View on GitHub.ref on mounted component returns HTML-Element instead of ReactWrapper
Open
#1459 opened on Jan 2, 2018
docshelp wantedv3 expected difference
Description
Current behavior
Imagine a component that renders a div with 3 anchor elements inside, each with their ref:
<div>
<a ref="element1" onClick="..."></a>
<a ref="element2" onClick="..."></a>
<a ref="element3" onClick="..."></a>
</div>
And you want to simulate an onclick behavior in a jest test.
So I mount the component:
var sut = mount(<Component>);
And then when I get the element wit hthe '.ref()' function, it does not return a ReactWrapper, but an HTMLAnchorElement, which does not have a .simulate or .prop?
However, the following does return a nice ReactWrapper and works as I wanted, but is not nice:
sut.find('a').at(0).simulate('click');
My best guess is that I do something wrong, but please forgive me if it is something silly.
Expected behavior
As the documentation says, return a ReactWrapper so I can act on it?
Your environment
?
API
- shallow
- mount
- render
Version
| library | version |
|---|---|
| Enzyme | 3.3.0 |
| React | 16.2.0 |
| Jest | 16.2.0 |
| enzyme-adapter-react-16 | 1.1.1 |
Adapter
- 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 ( )