How can I wrap a hook with a necessary Provider?
Hi @stramel, you can use the wrapper option of renderHook to wrap the test component in anything you want. An example of using a context Provider can be seen in our test suite
const wrapper = ({ children }) => (
<YourContext.Provider value="some context">{children}</YourContext.Provider>
)
const { result } = renderHook(() => useYourHook(), { wrapper })
Please feel free to submit a PR improving the docs as some examples are definitely missing.
@mpeyper Thank you for the answer. This is indeed what I was looking for. I will try to get a PR out for this in the near future.
Thanks. I've added an item to #19 for wrapper documentation. I'll close this one now and any PR can be made against that.
Most helpful comment
Hi @stramel, you can use the
wrapperoption ofrenderHookto wrap the test component in anything you want. An example of using a contextProvidercan be seen in our test suitePlease feel free to submit a PR improving the docs as some examples are definitely missing.