簡體   English   中英

AngularJS路由測試未知提供程序

[英]AngularJS routing test Unknown provider

我正在嘗試像這樣在路由器上設置茉莉花測試

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'
],

現在,當我開始測試因果報應時,它給了我錯誤:

錯誤:[$ injector:unpr]未知提供程序:$ routeProvider <-$ route

我的整個JS代碼都封裝在IIFE中,所以我什至沒有一個全局變量(我不知道這是否重要)。

為什么我有這個錯誤,我做錯了什么?

更改為

describe('Testing Routes', function () {
beforeEach(module('myApp'));
it('should map routes to controllers and templates', function($route) {
  expect($route.routes['/'].controller).toBe('mainPageCtrl');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM