{
  "$type": "site.standard.document",
  "path": "/testing-with-react-context/",
  "publishedAt": "2016-06-29T19:09:49.000Z",
  "site": "at://did:plc:6gssgguzeecdttuw4gpdshg2/site.standard.publication/self",
  "tags": [
    "react",
    "javascript",
    "testing"
  ],
  "textContent": "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.\n\nOur 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.\n\nOur wrapper code ended up looking like:\n\n[Embedded code (GitHub Gist)]\n\nThis takes any component and lets you wrap it with a context. In our tests we can provide a context and then wrap the control.\n\n[Embedded code (GitHub Gist)]\n\nThis renders a DOM based on the context. We can then assert that the proper items are rendered.\n\nRead the original post with all embeds and interactive content at https://rants.broonix.ca/testing-with-react-context/",
  "title": "Testing with React context"
}