Testing React Functional Component with Hooks using Jest

前端 未结 5 1850
傲寒
傲寒 2020-12-05 06:39

So I\'m moving away from class based components to functional components but am stuck while writing test with jest/enzyme for the methods inside the functional components wh

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-05 06:58

    Instead of isLoginDisabled state, try using the function directly for disabled. Eg.

    const renderSigninForm = () => (
    <>
      
    );

    When I was trying similar thing and was trying to check state(enabled/disabled) of the button from the test case, I didn't get the expected value for the state. But I removed disabled={isLoginDisabled} and replaced it with (password.length < 8 || !validateEmail(email)), it worked like a charm. P.S: I am a beginner with react, so have very limited knowledge on react.

提交回复
热议问题