I use CSSTransitionGroup to animate an element when it appears in the DOM, or when it exits the DOM. It works well.
Now - I want to unit test this component. I create a temporary DOM node, and I attach it to <body> , I transfer my component to it, and then I perform some actions. As a result, I expect the DOM node child to disappear.
Problem: Animation classes are applied, and the component is stored in the DOM until the end of the CSS animation. This means that my test must also wait a few hundred milliseconds before I can claim that this element has disappeared. I cannot do this - I want my tests to be fast, since these are unit tests.
Question: Is there a way to disable CSS transitions without adding additional parameters for my component?
What I tried: Module testing itself works well. I can get rid of the animation by passing a parameter to my component, which will cause it not to use CSSTransitionGroup . So the worst case scenario - I will do just that. But I'm looking for a better solution.
I could also claim that the classes -enter "/" - enter-active "/" - leave "/" - leave-active "are present in the corresponding element. This seems a bit hacked, although, as I could imagine, an error where these classes will be applied, but the element will remain in the DOM. I would prefer not to resort to this approach.
unit-testing reactjs reactcsstransitiongroup
kamituel
source share