【发布时间】:2018-05-19 00:21:18
【问题描述】:
我正在尝试像这样在路由器上设置茉莉花测试
it('should map routes to controllers and templates', function() {
inject(function($route) {
module('igt');
expect($route.routes['/'].controller).toBe('mainPageCtrl');
expect($route.routes['/'].templateUrl).toEqual('html/pages/main.html');
// otherwise redirect to
expect($route.routes[null].redirectTo).toEqual('/')
});
});
我的路由器文件是(只是开始,因为它很长):
(function () {
'use strict';
angular
.module('igt')
.config(configure);
configure.$inject = ['$routeProvider', '$httpProvider'];
function configure($routeProvider, $httpProvider) {
$routeProvider
.when('/', {
templateUrl: 'html/pages/main.html',
controller: 'mainPageCtrl'
})
我确实在 karma.conf.js 文件中注入了这些文件:
// list of files / patterns to load in the browser
files: [
'../../node_modules/angular/angular.js',
'../../node_modules/angular-mocks/angular-mocks.js',
'../app.js',
'../router.js',
'unit/*.js'
],
现在当我用 karma start 开始测试时,它给了我错误:
错误:[$injector:unpr] 未知提供者:$routeProvider
我的整个 JS 代码都封装在 IIFE 中,所以我连一个全局变量都没有(我不知道这是否重要)。
为什么我有这个错误我做错了什么?
【问题讨论】:
标签: angularjs testing jasmine karma-runner router