title: clear mocks between tests
body: <p>I fail to understand how jest works.</p>
  
  <p>consider the following setup.
  I have a "dependency" module like so :</p>
  
  <p><strong>dependency.js</strong></p>
  
  <pre><code>function doSomething(y) {
      console.log(y);
  }
  
  export {doSomething}
  </code></pre>
  
  <p>I have a module that uses this dependency :</p>
  
  <p><strong>MyModule.js</strong></p>
  
  <pre><code>import { doSomething } from './dependency';
  
  let alreadyDid;
  
  export default (x) =&gt; {
      if (alreadyDid)
          throw "error";
  
      doSomething(x * 2);
      alreadyDid = true;
  }
  </code></pre>
  
  <p>my test file look like the following  (I'm using require &amp; jest.resetModules in order to reset the module "state")</p>
  
  <p><strong>MyModule.test.js</strong></p>
  
  <pre><code>jest.mock('./dependency', () =&gt; ({doSomething: jest.fn()}))
  import { doSomething } from './dependency';
  
  let myModuleDo;
  
  describe('myModule', () =&gt; {
      beforeEach(() =&gt; {
          myModuleDo = require('./MyModule').default;
          jest.resetModules();
      });
  
      it('calls the dependency with double the input', () =&gt; {
          myModuleDo(2);
  
          expect(doSomething).toBeCalledWith(4);
      });
  
      it('calls the dependency with double the input', () =&gt; {
          myModuleDo(1);
  
          expect(doSomething).toBeCalledWith(2);
    });
  });
  </code></pre>
  
  <p>The problem is that the second test always failed, with the actual count as 4, as if it remembers the first call.
  when I switch between the 2, I get the opposite (2 instead of 4).</p>
  
  <p>I tried using mockReset() in afterEach, but then the second test fail on "not called".</p>
  
  <p>any idea what's happen here ?</p>
  
  <p><strong>UPDATE</strong>
  I realized I need to replace the "import" with require in order to get a new mock in each test.</p>
  
  <p>so now I'm confused - most of the jest examples are with "import" rather than "require". I almost don't see examples, or patterns explaining we need to use require in order to properly use the jest.fn(). </p>
  
  <p>What am I missing </p>