-1

I have the next hook

const useFetch => {
  let { state, dispatch } = useContext(AppContext);

  const fetch1 = async () => {
  ...code to fetch data (mocked)
  }
  const fetch2 = () => {
  ...
  }
  return {
    fetch1,
    fetch2,
    ...
  };
};

export default useFetch;

I need to create jest test but i can't do it directly because it break the rules of hooks, and I can't render it because it not have UI to render, it's only fetch data to store to the context.

Can anyone help me to understand how to do it?

Thanks in advance and sorry for my english.

skyboyer
  • 15,149
  • 4
  • 41
  • 56
Shoke
  • 3
  • 4

1 Answers1

0

You could create a wrapper component for test purpose only and work with that. However Testing Library has a great tool for that, hooks-testing-library. It might be a good addition to your project if you have more hooks to test.

slaid3r
  • 136
  • 6