Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 配置块中$routeprovider解析的jasmine测试_Angularjs_Unit Testing_Karma Jasmine_Route Provider - Fatal编程技术网

Angularjs 配置块中$routeprovider解析的jasmine测试

Angularjs 配置块中$routeprovider解析的jasmine测试,angularjs,unit-testing,karma-jasmine,route-provider,Angularjs,Unit Testing,Karma Jasmine,Route Provider,我的模块配置块中有以下内容: var appModule = angular.module('myApp',['ngRoute']) .config(['$httpProvider', '$routeProvider', '$locationProvider', '$translateProvider', function ($httpProvider, $routeProvider, $locationProvider, $translateProvider) { $location

我的模块配置块中有以下内容:

var appModule = angular.module('myApp',['ngRoute'])
.config(['$httpProvider', '$routeProvider', '$locationProvider', '$translateProvider', function ($httpProvider, $routeProvider, $locationProvider, $translateProvider) {

    $locationProvider.html5Mode(true)

    $routeProvider
        .when('/services/main', {templateUrl: '/services/main/html/main.html', controller: 'MainCtrl', resolve: {
            myVar: function (varService) {
                return varService.invokeService();
            }
        }})
}])
规范文件:

describe("Unit Testing: config - ", function() {

var appModule;
var routes;

beforeEach(function() {
    appModule = angular.module("myApp");
});

it('should test routeProvider', function() {

      inject(function($route, $location, $rootScope) {
          routes = $route;
      });
    }); 
});
但是,在运行测试时,我得到以下错误:

Unit Testing: config -  should test routeProvider FAILED
Error: [$injector:unpr] http://errors.angularjs.org/1.2.15/$injector/unpr?p0=%24routeProvider%20%3C-%20%24route
    at Error (native)

我的karma配置包括angular-route.min.js文件。任何建议都会有帮助。

使用angular.mock.module而不是angular.module解决了该问题

appModule = angular.mock.module("myApp");
我发现我们应该使用mock来注入模块,它包括配置以及使用as模块注册新模块的位置。因此,如果引用的是已注册的模块,则应使用angular.mock.module

文件说:

This function registers a module configuration code. It collects the configuration information which will be used when the injector is created by inject.