How to write test case using React Testing Library for useEffect which is dependent on useState values

Viewed 14

I am trying to write a test case for an useEffect, which gets into action when the flag or headFlag gets trigerred to true. Now to test this Im not getting how to mock the state for headflag and flag to true ? Any idea will be helpful.

const [headFlag, SetheadFlag] = useState(false);
const [Flag, SetFlag] = useState(false); 

     React.useEffect(() => {
        if (headFlag === true && Flag === true) {
          setselectOptions(UpdateOptions)
        } 
      }, [Flag, headFlag])
0 Answers
Related