How to test a react component that is dependent on useContext hook?

In general, using hooks shouldn’t change testing strategy much. The bigger issue here actually isn’t the hook, but the use of context, which complicates things a bit. There’s a number of ways to make this work, but only approach I’ve found that works with ‘react-test-renderer/shallow’ is to inject a mock hook: import ShallowRenderer from ‘react-test-renderer/shallow’; … Read more