Skip to content

find(Component|'selector') not working on conditionally rendered components. #2387

@shaleenmundra

Description

@shaleenmundra

#1147 # Current behavior
I cannot find(Component|".selector") but I can see it via html() and via .contains()

code

<input type='text' name='Name'>

{isPasswordRequired && 
<input type='password' name='Password'>}

the isPasswordRequired value is set to true with a button click.

I simulated the button click and the boolean is set to true but still the .find() method is not able to find the given component.

test

//simulate button click
wrapper.update();

//works fine
wrapper.contains('input[name="Password"]'); 

// gives error .props() meant to be run on 1 node, 0 found instead.
wrapper.find('input[name="Password"]').props(); 

Expected behaviour

.contains(), .find() should return consistent results.

Your environment

MacOS mojave 10.14.6
node : v12.12.2
npm: 6.14.1

API

  • shallow
  • mount
  • render

Version

library version
enzyme 3.9.0
react 16.8.6
react-dom 16.8.6
react-test-renderer
adapter (below)

Adapter

  • enzyme-adapter-react-16
  • enzyme-adapter-react-16.3
  • enzyme-adapter-react-16.2
  • enzyme-adapter-react-16.1
  • enzyme-adapter-react-15
  • enzyme-adapter-react-15.4
  • enzyme-adapter-react-14
  • enzyme-adapter-react-13
  • enzyme-adapter-react-helper
  • others ( )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions