2

I got a custom hook which return a function

export function useMyCustomHook = (dispatch) => () => {... some things with dispatching to store };

I'm trying to use the return value like this in a jest test:

  const result = renderHook(() => useMyCustomHook(useDispatch()));
  console.log(result.current);

but result.current is undefined. So how can I actually get the return value?

skyboyer
  • 22,209
  • 7
  • 57
  • 64
CodeMonkey
  • 11,196
  • 30
  • 112
  • 203

1 Answers1

4

According to react-hooks-testing-library renderHook returns an object with result, so to access it:

const { result } = renderHook(() => useMyCustomHook(useDispatch()));
console.log(result.current);
Jose Felix
  • 970
  • 5
  • 7
  • Now if you want to try and look at a follow up question: https://stackoverflow.com/questions/59476912/testing-custom-hook-invariant-violation-could-not-find-react-redux-context-val – CodeMonkey Dec 25 '19 at 09:21