-
-
Notifications
You must be signed in to change notification settings - Fork 2k
ReactWrapper::setState() can only be called on the root #1289
Copy link
Copy link
Closed
Labels
API: mountfeature requestIssues asking for stuff that would be semver-minorIssues asking for stuff that would be semver-minorhelp wanted
Description
Preface
I had went through #814 and #361 , but I still don't get the answer I want.
Explanation
I know you may say that in practice you should only test a child component in isolation, but I'm in a situation where the child component cannot be rendered without the parent component.
For example, because I'm using React Material-UI, I got to mount the element-to-be-tested inside a theme provider, if not error will be thrown during mounting :
const wrapper = mount(
<MuiThemeProvider>
<SubjectListView subjects={subjects}/>
</MuiThemeProvider>);Problem
I need to set the state of SubjectListView but then I got this ReactWrapper::setState() can only be called on the root error.
Conclusion
I really hope I can call setState() on child element, if not I have to wrap all my components with a <MuiThemeProvider> which is obviously not a good thing.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
API: mountfeature requestIssues asking for stuff that would be semver-minorIssues asking for stuff that would be semver-minorhelp wanted