title: React & Jest global.confirm not updating between tests
body: <p>I have an existing application that I am trying to write tests for. I have a component function that uses a window.confirm box to get user input (not my code) like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>if (window.confirm('Are you sure to unassign?')) {
      NetworkWebAPIUtils.unassignSeat(this.state.seatnetwork.seat.id, this.state.seatnetwork.network.id, this.props.rank);
  }
  </code></pre>
  
  <p>I am trying to write tests for both paths:</p>
  
  <pre class="lang-js prettyprint-override"><code>it('should call endpoint when user selects yes', function () {
      global.confirm = jest.fn(() =&gt; true);
      seatUpdateRow.instance().handleChangeAssigned({target: {value: true}});
  
      expect(NetworkWebAPIUtils.unassignSeat.mock.calls.length).toBe(1);
      expect(NetworkWebAPIUtils.unassignSeat.mock.calls[0].length).toBe(3);
      expect(NetworkWebAPIUtils.unassignSeat.mock.calls[0][0]).toBe(1234);
      expect(NetworkWebAPIUtils.unassignSeat.mock.calls[0][1]).toBe(5678);
      expect(NetworkWebAPIUtils.unassignSeat.mock.calls[0][2]).toBe(1);
  });
  
  it('should not call endpoint when user selects no', function () {
      global.confirm = jest.fn(() =&gt; false);
      seatUpdateRow.instance().handleChangeAssigned({target: {value: true}});
  
      expect(NetworkWebAPIUtils.unassignSeat).not.toHaveBeenCalled();
  });
  </code></pre>
  
  <p>The problem is that global.confirm will not update for the second test. If I set the first test to <code>false</code> then it obviously fails but the second one passes. If I set the first to <code>true</code> then the first passes but the second fails because <code>global.confirm = jest.fn(() =&gt; false)</code> doesn't actually cause window.confirm to evaluate to false. If I comment out the first then the second passes just fine.</p>
  
  <p>I have tried mocking window.confirm and I get the exact same behavior.</p>