我想在Karma中模拟一个功能,它在点击下载按钮后返回一个文件.我有以下AngularJS控制器:
var secure = angular.module('secure', []);
secure.controller('ProcedureController', ProcedureController);
ProcedureController.$inject = ['$controller', '$rootScope', '$scope', '$http'];
function ProcedureController($controller, $rootScope, $scope, $http) {
... // Controller does more stuff
var href = window.location.href.split('/');
var baseUrl = href[0] + '//' + href[2];
var url = baseUrl + "/secure/regulations";
$http.get(url)
.success(function (data) {
$scope.questions = data[0];
})
$scope.download = function (msg) {
window.location = url + "/" + msg + "/attachment";
}
}
Run Code Online (Sandbox Code Playgroud)
window.location对象只调用一个RESTful服务,直接为他提供所需的文件.这基本上就是我的尝试测试:
describe('ProcedureController', function () {
beforeEach(module('secure'));
beforeEach(inject(function ($rootScope, $http, $controller, $injector) { …
Run Code Online (Sandbox Code Playgroud)