我有一个返回函数的自定义钩子
export function useMyCustomHook = (dispatch) => () => {... some things with dispatching to store };
我正试图在玩笑测试中使用这样的返回值:
const result = renderHook(() => useMyCustomHook(useDispatch()));
console.log(result.current);
但result.current
未定义。那么我怎么才能真正获得返回值呢?
答案 0 :(得分:0)
根据react-hooks-testing-library renderHook
返回带有结果的对象,因此可以访问它:
const { result } = renderHook(() => useMyCustomHook(useDispatch()));
console.log(result.current);