enzyme icon indicating copy to clipboard operation
enzyme copied to clipboard

How to test InteracationManager.runAfterInteractions().then(()=>this.myMethod(this.props)}) using jest

Open DineshSuram opened this issue 5 years ago • 4 comments

public componentDidMount() {
    const { animateOnDidMount } = this.props;

    if (animateOnDidMount) {
      InteractionManager.runAfterInteractions().then(() => {
        this.myMethod(this.props);
      });
    }
  }

Iam using jest. I have created a component like this let sideComp=shallow(<MyComponent/>. It is react-native project. I need to invoke myMethod for improving codecoverage. how can I test this code and what assert I need to keep.

DineshSuram avatar May 23 '19 10:05 DineshSuram

I have no idea what "IteractionManager" is, or what "runAfterInteractions" does. Can you elaborate?

ljharb avatar May 24 '19 19:05 ljharb

did you figure it out?

sibelius avatar Dec 05 '19 13:12 sibelius

Did you find any way to handle this when running with Jest?

MateusAndrade avatar Apr 13 '20 17:04 MateusAndrade

I got mine playing nicely like this:

const useIsPageTransitioning = () => {
  const [isTransitioning, setIsTransitioning] = React.useState(true);
  React.useEffect(() => {
    const interaction = InteractionManager.runAfterInteractions(() => {
      setIsTransitioning(false);
    });
    return () => interaction.cancel()
  }, []);

  return isTransitioning;
};

Dakuan avatar Feb 11 '21 17:02 Dakuan