Closed janderssen closed 5 years ago
Or another option would be to set the width and height in the tests if you are able to. And also there is another much better option than this toggle, React-Toggle.
I'm having this issue too. Tried setting width / height per this unrelated thread: https://github.com/testing-library/react-testing-library/issues/353#issuecomment-510074776
no luck.
My solution was to pass a static height / width prop to the toggle which prevents setDimensions from being called.
Here's the bit of code causing the issue in the toggle:
componentDidMount() {
if (this.props.width && this.props.height) {
return;
}
this.setDimensions();
if (this.props.recalculateOnResize) {
this.resizeObserver = new ResizeObserver((ent, obs) => {
this.setDimensions();
});
this.resizeObserver.observe(this.parent);
}
}
This is still an ongoing issue. This has proved to be a big problem for our production environment suddenly.
Get a infinite render loop when using jest for testing if I use this component:
[Invariant Violation: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.]
To work around for the moment, I remove the this.setDimensions(); from componentDidUpdate, but not sure if this is the correct fix as I dont know the Toggle code, just verifying if this seems to be an ok fix by the author?