title: Testing a React Store with Jest
body: <p>I'm trying to test my React store using Jest (I'm adhering to the Flux architecture) but am not sure when I need to mock up a store function. To illustrate my point, here's a portion of my store code: </p>
  
  <pre><code>export default class AdminStore extends EventEmitter {
     constructor() {
         super();
         this.users = [];
         this.userTotal = 0;
         this.profile = {};
  
         AdminDispatcher.register((payload) =&gt; {
             switch (payload.eventName) {
                 case AdminConstants.USER_TOTAL:
                     this.userTotal = payload.total;
                     this.emit('change');
                 break;
  
                 case AdminConstants.ALL_USERS:
                     this.users = payload.users;
                     this.emit('change');
                 break;
  
                 case AdminConstants.FETCH_USER:
                     this.profile = payload.profile;
                     this.emit('change');
                 break;
  
                 default:
  
                 break;
             }
             return true;
         });
     }
  
     syncUsers() {
         return this.users;
     }
  
     syncUserTotal() {
         return this.userTotal;
     }
  
     syncProfile() {
         return this.profile;
     }
  }
  </code></pre>
  
  <p>Here's a snippet of my Jest test code:</p>
  
  <pre><code>jest.dontMock('../AdminStore.js');
  jest.dontMock('../../constants/AdminConstants.js');
  
  describe('AdminStore', () =&gt; {
      let callback;
      let AdminStore;
      let AdminDispatcher;
      let AdminConstants = require('../../constants/AdminConstants.js');
  
      beforeEach(() =&gt; {
          AdminStore = require('../AdminStore.js');
          AdminDispatcher = require('../../dispatcher/AdminDispatcher.js');
          callback = AdminDispatcher.register.mock.calls[0];
      });
      it ('should initialize with a user total of 0', () =&gt; {
          let total = AdminStore.syncUserTotal();
          expect(total).toEqual(0);
      });
  });
  </code></pre>
  
  <p>My Jest output for this test looks like this:</p>
  
  <pre><code>● AdminStore › it should initialize with a user total of 0
    - TypeError: undefined is not a function
      at Spec.&lt;anonymous&gt; (/Users/seanchen/karma/admin-new/src/js/stores/__tests__/AdminStore-test.js:34:32)
      at jasmine.Block.execute (/Users/seanchen/karma/admin-new/node_modules/jest-cli/vendor/jasmine/jasmine-1.3.0.js:1065:17)
      at jasmine.Queue.next_ (/Users/seanchen/karma/admin-new/node_modules/jest-cli/vendor/jasmine/jasmine-1.3.0.js:2098:31)
      at null._onTimeout (/Users/seanchen/karma/admin-new/node_modules/jest-cli/vendor/jasmine/jasmine-1.3.0.js:2088:18)
  1 test failed, 1 test passed (2 total)
  Run time: 3.493s
  </code></pre>
  
  <p>Does <code>AdminStore.syncUserTotal()</code> need to be mocked? I'm really not sure why it's undefined.</p>