Testing with React context
Broonix
June 29, 2016
Last we I outlined how to use react's context feature in an application. This week I'll show you how to ensure you can test components that use react context.
Our test setup uses jsDom and Chai to render and test our components. You need to wrap any component so that it can access a mock context.
Our wrapper code ended up looking like:
[Embedded code (GitHub Gist)]
This takes any component and lets you wrap it with a context. In our tests we can provide a context and then wrap the control.
[Embedded code (GitHub Gist)]
This renders a DOM based on the context. We can then assert that the proper items are rendered.
Read the original post with all embeds and interactive content at https://rants.broonix.ca/testing-with-react-context/
Discussion in the ATmosphere