title: Testing React Component Strategy
body: <p>What is the best way to test React's Components in Unit Tests?</p>
  
  <p>The first problem is decorators (or HOCs). We don't want to test them, but without them it is really hard to mount deeply to test how it works as a components; but in order to make them work we have to mock all chain of Providers (which is ~3 components in our case, plus contexts, etc), and again, it is too fragile from my point of view.</p>
  
  <p>Next question is about the logic inside components. I know, there are tons of articles with cool advice like "don't use logic inside your components", but we often need to maintain local state (like banners, etc). Should it be tested just with <code>shallowMount</code>, or it doesn't cost it too? Also lifecycle methods, if we start to check it, doesn't it make our tests too brittle and too much know about implementation?</p>
  
  <p>And the last question is about the markup. Should we check anything inside the React Component? I read all sorts of tutorials, and I think that finding by tag is the worst example ever (I don't even want to go into details here). Jest snapshot feature for me doesn't seem a good choice too (I see absolutely the same problems here too). What I see could be helpful – just checking that different components are rendered when difference props are passed (like <code>Loader</code> and <code>Offer</code>, for instance, respectively), but sometimes they are children of some container itself, and shallowRendering doesn't work, which takes us back to the initial point.</p>
  
  <p>To conclude, I see the point only in two things:</p>
  
  <ol>
  <li>Testing logic for internal state (invoking methods and looking into new state)</li>
  <li>Looking at rendering of components which render depending on props.</li>
  </ol>
  
  <p>Second point can be really hard (because of deep nested children), so for now I am leaning towards rendering just a component (check that it didn't fail – in a shallow way), and checking logic by invoking methods and checking state after.</p>
  
  <p>What are your strategies?</p>