Error: Invariant Violation: findAllInRenderedTree(…): instance must be a composite component

爷,独闯天下 提交于 2019-12-01 16:27:26

A composite component is a component which contains React Component (not div, span, ...) The method 'findRenderedDOMComponentWithTag' takes in parameter a composite component.

Try to parse the component directly in your case (jquery, js, ...) because it is not a composite one

This is late, but I just ran into this, and I haven't found a great answer for it.

My solution was to make a wrapper component in the test file

import { Component } from "react";
class Wrapper extends Component {
  render() {
    return <YourComponent {...this.props} />
  }
}

and instead of calling

TestUtils.renderIntoDocument(
    <YourComponent />
);

call

TestUtils.renderIntoDocument(
    <Wrapper />
);

Doing this ensures that your component is a composite component and isn't a stateless function.

Hope this helps anyone else in the future!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!