我有一个非常简单的控制器:
angular.module("myApp").controller("TestCtrl", function ($scope) {
$scope.value = 5;
$scope.func = function () {
return 10;
};
});
我即将开始学习如何使用业力进行单元测试..问题是myApp有这些配置 - 特别是最后一个:
angular.module("myApp",["ui.router", "blueimp.fileupload", "ui.bootstrap"]);
.config(function( $locationProvider ) {
$locationProvider.html5Mode( true );
})
.config(function ($urlRouterProvider) { })
.config(function ($stateProvider) {
$stateProvider
.state("blabla", { url : "someurl", templateUrl : "templatePath" });
})
.config(function ($httpProvider) {
$httpProvider.interceptors.push("httpInterceptor");
$httpProvider.interceptors.push("htmlTemplateCacheBuster");
});
我开始编写一些测试代码......
describe("TestCtrl", function($log) {
"use strict";
it("first test", function () {
expect(1).toEqual(1);
});
beforeEach(angular.mock.module("myApp"));
beforeEach(inject(function() {}));
});
一切正常但是当我添加最后一行时,尝试开始注入的东西我得到了这个错误..我发现它与$ httpProvider的最后一个配置有关..
e 44.0.2403 (Windows 7 0.0.0) TestCtrl first test FAILED
Error: [$injector:unpr] Unknown provider: htmlTemplateCacheBusterProvider <- htmlTemplateCacheBuster <- $http <- $templateFactory <- $view <- $state
http://errors.angularjs.org/1.3.9/$injector/unpr?p0=htmlTemplateCacheBusterProvider%20%3C-%20htmlTemplateCacheBuster%20%3C-%20%24http%20%3C-%20%24templateFactory%20%3C-%20%24view%20%3C-%20%24state
at C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:63:12
at C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:3994:19
at Object.getService [as get] (C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:4141:39)
at C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:3999:45
at Object.getService [as get] (C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:4141:39)
at C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:8777:23
at forEach (C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:323:20)
at $HttpProvider.$get (C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:8775:5)
at Object.invoke (C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:4182:17)
at C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:4000:37
Chrome 44.0.2403 (Windows 7 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.028 secs / 0.015 secs)
如果有人能帮助我,我会很感激!我正在使用Angular和Mocks v 1.3.9和ui-router 0.2.13 ...
由于