title: Is there a faster way to reset a mock when testing with Jest?
body: <p>I'm writing some React/Flux code and using Jest to test it. So far it's been great, except my test are already taking a long time to complete.</p>
  
  <p>The culprit seems to be resetting the mocks in between each test.</p>
  
  <p>My general set up will look something like this:</p>
  
  <pre><code>jest.dontMock('react');
  jest.dontMock('../Widget.jsx');
  
  describe('Widget', function() {
    var React, TestUtils, Widget, WidgetStore;
  
    beforeEach(function() {
      React = require('react/addons');
      TestUtils = React.addons.TestUtils;
      WidgetStore = require('../WidgetStore');
      Widget = require('../Widget');
    });
  
    it('should fetch initial state from the store', function() {
      WidgetStore.getDoobles.mockReturnValueOnce({});
  
      var widget = TestUtils.renderIntoDocutment(
        &lt;Widget /&gt;
      );
  
      expect(WidgetStore.getDoobles.mock.calls.length).toBe(1);
    });
  
    it('should refresh its data when clicked', function() {
      WidgetStore.getDoobles.mockReturnValueOnce({});
  
      var widget = TestUtils.renderIntoDocutment(
        &lt;Widget /&gt;
      );
  
      WidgetStore.getDoobles.mockReturnValueOnce({'foo': 'bar'});        
  
      TestUtils.Simulate.click(widget);
  
      expect(WidgetStore.getDoobles.mock.calls.length).toBe(2);
    });
  });
  </code></pre>
  
  <p>In my example if I don't reload the store in between the two tests I will get the wrong result for the number of calls to <code>getDoobles</code>, which makes sense since it would be the same object.</p>
  
  <p>But reloading the mock takes a bit of time and if I do lots of tests then they end up being slow.</p>
  
  <p>I would love to just clone the object or call a reset function. There is a reset function for an individual function (<code>mockClear()</code>) but there doesn't seem to be a global reset for the whole object. And I can't clone the object because the clone isn't the same object as the one that my React component is accessing, so none of the calls will get registered.</p>
  
  <p>Which brings up the other issue. It seems I need to reload everything in the dependency chain. If I were to just re-require <code>WidgetStore</code> then the object I have access to doesn't seem to be the same object that <code>Widget</code> has access to.</p>
  
  <p>If I just reload <code>WidgetStore</code> and <code>Widget</code> then I will often get errors which seem to be caused by <a href="https://stackoverflow.com/questions/27153166/typeerror-when-using-react-cannot-read-property-firstchild-of-undefined">having two copies of React loaded</a>. So I end up having to reload React each time as well.</p>
  
  <p>So is there a better way of doing this?</p>