I have an Angularjs application that uses simple javascript confirm before executing some actions.
function TokenControll
In unit tests you can mock the $window object like this:
Your test:
beforeEach(function() {
module('myAppName');
inject(function($rootScope, $injector) {
$controller = $injector.get('$controller');
$scope = $rootScope.$new();
var windowMock = { confirm: function(msg) { return true } }
$controller('UsersCtrl', { $scope: $scope, $window: windowMock });
});
});
Your controller:
myAppName.controller('UsersCtrl', function($scope, $window) {
$scope.delete = function() {
var answer = $window.confirm('Delete?');
if (answer) {
// doing something
}
}
});