title: Javascript.confirm() and Angularjs Karma e2e test
body: <p>I have an <strong>Angularjs</strong> application that uses simple javascript confirm before executing some actions. </p>
  
  <h2>Controller:</h2>
  
  <pre><code>function TokenController($scope) {
    $scope.token = 'sampleToken';
  
    $scope.newToken = function() {
      if (confirm("Are you sure you want to change the token?") == true) {
        $scope.token = 'modifiedToken';
      }
    };
  }
  </code></pre>
  
  <h2>View:</h2>
  
  <pre><code>&lt;div id="tokenDiv"&gt;
    Token:{{token}} &lt;button ng-click="newToken()"&gt;New Token&lt;/button&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Now I want to have an end to end test to check the token is being replaced correctly in the view. How can I intercept the <code>javascript.confirm()</code> call so it doesn't stop the execution of the test?</p>
  
  <h2>Test:</h2>
  
  <pre><code>it('should be able to generate new token', function () {
     var oldValues = element('#tokenDiv').text();
     element('button[ng-click="newToken()"]').click(); // Here the javascript confirm box pops up.
     expect(element('#tokenDiv').text()).not.toBe(oldValues);
  });
  </code></pre>
  
  <p>So far I've tried to redefine the <code>window.confirm</code> function but then the actual call complains that it is undefined.</p>
  
  <p>I also wanted to set up a Jasmine spy on <code>window.confirm</code> but in the following syntax <code>spyOn(window, 'confirm');</code> it gives me an error saying you can not spy on <code>null</code>.</p>
  
  <p>How would I go about making such test work?</p>