title: How do I use Jest to test a React view wired to store?
body: <p>I have a <strong>React view</strong> that communicates with a <strong>store</strong>. I've successfully tested views and stores separately, but not in combination. </p>
  
  <p>I followed the <a href="https://stackoverflow.com/a/25557322/154065">structure documented here</a> but received a <strong>TypeError</strong>. It looks like Jest is trying to register the store as a component even if I use <code>dontMock</code>. </p>
  
  <pre><code>Using Jest CLI v0.2.0
   PASS  __tests__/unit/spec/stores/ViewStore-spec.js (0.248s)
   FAIL  __tests__/unit/spec/components/View-spec.react.js (0.942s)
  undefined
  ● View › it defaults to zero unread
    - TypeError: /Users/matnorri/dev/projects/matnorri/web-client/src/app/scripts/components/View.react.js: /Users/matnorri/dev/projects/matnorri/web-client/src/app/scripts/stores/ViewStore.js: Cannot call method 'register' of undefined
          at /Users/matnorri/dev/projects/matnorri/web-client/src/app/scripts/stores/ViewStore.js:43:31
          at Object.runContentWithLocalBindings (/Users/matnorri/dev/projects/matnorri/web-client/node_modules/jest-cli/src/lib/utils.js:357:17)
          ...
  </code></pre>
  
  <p>I've included what I believe is the relevant code below, but can provide it in its entirety if necessary. </p>
  
  <p><strong>View Jest Test</strong></p>
  
  <pre><code>jest.dontMock('../../../../src/app/scripts/components/View.react');
  jest.dontMock('../../../../src/app/scripts/stores/ViewStore');
  
  describe('View', function() {
  
    var React;
    var TestUtils;
    var ViewComponent;
    var View;
  
    beforeEach(function() {
      React = require('react/addons');
      TestUtils = React.addons.TestUtils;
      ViewComponent =
        // Tried both lines with same effect.
        // require('../../../../src/app/scripts/components/View.react.js');
        require('../../../../src/app/scripts/components/View.react');
      View = TestUtils.renderIntoDocument(&lt;ViewComponent /&gt;);
    });
  
    it('defaults to zero unread', function() {
      View._toString = jest.genMockFunction();
      View._onChange();
      expect(View.state.unread).toBe(0);
    });
  });
  </code></pre>
  
  <p>Thank you!</p>