enzymejs/enzyme

.ref on mounted component returns HTML-Element instead of ReactWrapper

Ouverte

#1 459 ouverte le 2 janv. 2018

 (4 commentaires) (0 réaction) (0 personne assignée)JavaScript (1 970 forks)batch import
docshelp wantedv3 expected difference

Métriques du dépôt

Stars
 (19 828 étoiles)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

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 ( )

Guide contributeur