enzyme: Enzyme 3 - Find Where does not work.

Hi, after update to v3, findWhere stopped working.

Following line throws ​​Method “props” is only meant to be run on a single node. 0 found instead.​​

wrapper.findWhere(w => w.prop('content') === 'Register').simulate('click')

This is the wrapper.debug() - shortened

​​​​​<Segment inverted={true}>​​​​​
...
  <Button type="button" onClick={[Function]} color="green" labelPosition="left" content="Register" icon="sign in" as="button">​​​​​
      ​​​​​ <button type="button" className="ui green icon left labeled button" disabled={[undefined]} onClick={[Function]} role="button" tabIndex={[undefined]}>​​​​​
      ​​​​​     <Icon name="sign in" as="i">​​​​​
      ​​​​​          <i aria-hidden="true" className="sign in icon" />​​​​​
      ​​​​​     </Icon>​​​​​
      ​​​​​     Register​​​​​
      ​​​​​  </button>​​​​​
   </Button>​​​​​
 ...
​​​</Segment>​​​​​

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 9
  • Comments: 20 (9 by maintainers)

Most upvoted comments

Thanks for looking into it. Based on a suggestion above, I have gotten it working using

let convertSponsored = wrapper
        .find('Confirm')
        .filterWhere(n => n.contains('Convert to Sponsored'));

The code that creates the wrapper is here:

let wrapper = mount(
      <CustomerDetails params={{orgId: mockOrganization.slug}} />,
      TestStubs.routerContext([{user: mockUser}])
    );

The component I was trying to find is here: https://github.com/getsentry/sentry/blob/master/src/sentry/static/sentry/app/components/confirm.jsx

So, it seems to be working fine using a two step .find then .filterWhere rather than a straight .findWhere using a two-part boolean expression (n.type === 'Confirm' && n.contains('....')).

Getting the same thing, I’m using mount:

react@16.0.0 enzyme@3.0.0

Jest setup file:

import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new Adapter() });