I have an Angularjs application that uses simple javascript validation before doing some things.
Controller:
function TokenController($scope) { $scope.token = 'sampleToken'; $scope.newToken = function() { if (confirm("Are you sure you want to change the token?") == true) { $scope.token = 'modifiedToken'; } }; }
View:
<div id="tokenDiv"> Token:{{token}} <button ng-click="newToken()">New Token</button> </div>
Now I want to pass the end test to verify that the token is correctly replaced in the view. How to intercept the javascript.confirm() call so that it does not stop the test execution?
Test:
it('should be able to generate new token', function () { var oldValues = element('#tokenDiv').text(); element('button[ng-click="newToken()"]').click();
So far I have been trying to override the window.confirm function, but then the actual call complains that it is undefined.
I also wanted to configure the Jasmine spy on window.confirm , but in the following syntax spyOn(window, 'confirm'); he gives me a message stating that you cannot keep track of null .
How can I do such a trial?
angularjs karma-runner jasmine angularjs-e2e
mrt May 7, '13 at 17:20 2013-05-07 17:20
source share