title: How do I reset mocked values in Jest?
body: <p>I am trying my hand jest and writing unit tests.
  I have written unit tests for couple of functions. These functions use an object of constants imported from a different file. So I have mocked these constants.</p>
  <pre><code>describe('testing helpers', () =&gt; {
  
      beforeEach(() =&gt; jest.resetModules());
  
      describe('reset board', () =&gt; {
          // first test using original constant values
          test('with default constants', () =&gt; {
              const game = {
                  board: [
                      [0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0]
                  ],
                  count: 0
              };
  
              const helper = require('./helper');
              expect(helper.resetBoard()).toEqual(game);
          });
  
          // second test using mocked constant values
          test('reset board', () =&gt; {
              const game = {
                  board: [
                      [0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0]
                  ],
                  count: 0
              };  
  
              jest.mock(&quot;./constants&quot;, () =&gt; ({ ROWS: 4, COLUMNS: 5 }));
  
              const helper = require('./helper');
              expect(helper.resetBoard()).toEqual(game);
          });
      });
  
      describe('make move', () =&gt; {
          // third test with original constant values
          test('player 1 move', () =&gt; {
  
              const testBoard = [
                      [0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0]
                  ];
              const testTurn = 'YELLOW';
              const testColumn = 0;
  
              const expectedBoard = [
                      [0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0],
                      [1, 0, 0, 0, 0, 0, 0]
                  ];
  
              const helper = require('./helper');
              helper.makeMove(testBoard, testTurn, testColumn);
              expect(testBoard).toEqual(expectedBoard);
          });
      });
  });
  </code></pre>
  <p>But when the third test which is in the second describe block is running it is picking up the mocked values instead of the original values. I thought this <code>beforeEach(() =&gt; jest.resetModules());</code> would reset the mocked values but it is not working.
  Please help with this.
  Any other tips for improving on the tests will be appreciated.</p>