Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in scryRenderedComponentsWithType #11855

Closed
pronebird opened this issue Dec 14, 2017 · 4 comments
Closed

Bug in scryRenderedComponentsWithType #11855

pronebird opened this issue Dec 14, 2017 · 4 comments

Comments

@pronebird
Copy link

pronebird commented Dec 14, 2017

scryRenderedComponentsWithType spits the following:

findAllInRenderedTree(...): instance must be a composite component

test case:

class Accordion extends React.Component {
  render() {
    return (<div>{ this.props.children }</div>);
  }
}
const tree = ReactTestUtils.renderIntoDocument(
      <div>
        <Accordion height={ 0 }>
          <div>Hello</div>
        </Accordion>
      </div>
);

const elements = ReactTestUtils.scryRenderedComponentsWithType(tree, Accordion);
expect(elements[0].clientHeight).to.be.equal(0);
@gaearon
Copy link
Collaborator

gaearon commented Dec 14, 2017

This doesn't tell us much (what is Accordion?)

Please provide a full reproducing project.

@pronebird
Copy link
Author

pronebird commented Dec 15, 2017

Accordion is any kind of component that inherits from React.Component. I updated my test. I wonder why none of internal React tests failed, either I don't understand documentation or none of this works.

@gaearon
Copy link
Collaborator

gaearon commented Jan 2, 2018

I think scryRenderedComponentsWithType() accepts a component instance as first argument, not a div.

I agree the API is confusing there. In practice most people are using Enzyme (https://airbnb.io/enzyme/) these days so I don't think we'll invest much work into fixing this. I encourage you to try Enzyme.

@gaearon
Copy link
Collaborator

gaearon commented Aug 9, 2018

I made the error message clearer in #13351.
Thanks for reporting.

@gaearon gaearon closed this as completed Aug 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants