react-hooks-testing-library

How to set initial state for useState Hook in jest and enzyme?

我只是一个虾纸丫 提交于 2020-02-23 10:32:15
问题 Currently Im using functional component with react hooks. But i unable to test the useState Hook completely. Consider a scenario like, in useEffect hook i'm doing api call and setting value in the useState. For jest/enzyme i have mock data to test but i unable to set initial state value for useState in jest. const [state, setState] = useState([]); I want to set initial state as array of object in jest. I could not find any setState function as similar like class component. 回答1: You can mock