簡體   English   中英

業力測試無法評估應用程序的角度路線

[英]Karma test failing on evaluating app for angular routes

在將AngularJS與RequireJS結合使用時設置Karma測試。 一切似乎都已設置,但在路由文件上標記了“ TypeError:'undefined'不是對象(正在評估'app.config')'錯誤。

需要配置main.js

 'use strict';

require.config({
  paths: {
    angular: '../../bower_components/angular/angular',
    angularAnimate: '../../bower_components/angular-animate/angular-animate',
    angularFoundationTpls: '../../bower_components/angular-foundation/mm-foundation-tpls',
    angularMocks: '../../bower_components/angular-mocks/angular-mocks',
    angularResource: '../../bower_components/angular-resource/angular-resource',
    angularRoute: '../../bower_components/angular-route/angular-route',
    app: 'app',
    domReady: '../../bower_components/domReady/domReady',
    foundation: '../../bower_components/foundation/js/foundation',
    igniteui: '../libs/igniteui/igniteui-angular',
    igniteuidirectives: 'directives/igniteui-directives',
    infragistics: '../libs/infragistics/infragistics',
    infragisticsdv: '../libs/infragistics/infragistics.dv',
    infragisticslob: '../libs/infragistics/infragistics.lob',
    infragisticscore: '../libs/infragistics/infragistics.core',
    jquery: '../../bower_components/jquery/dist/jquery',
    jqueryui: '../../bower_components/jquery-ui/jquery-ui',
    modernizr: '../../bower_components/modernizr/modernizr',
    text: '../../bower_components/requirejs-text/text',
    tokenInput: '../libs/tokeninput/src/jquery.tokeninput',
    underscore: '../../bower_components/underscore/underscore'
  },

    shim: {
        'angular': {
            deps: ['jquery'],
            exports: 'angular'
        },

        'angularAnimate': ['angular'],

        'angularFoundationTpl': {
            deps: ['foundation', 'angular']
        },

        'angularMocks': {
            deps: ['angular'],
            exports: 'angular.mock'
        },

        'angularResource': ['angular'],

        'angularRoute': ['angular'],

        'app': {
            exports: 'app'
        },

        'foundation': {
            deps: ['jquery', 'modernizr'],
            exports: 'Foundation'
        },

        'igniteui': {
            deps: ['infragisticslob']
        },

        'infragisticsdv': {
            deps: ['infragisticscore']
        },

        'infragisticslob': {
            deps: ['infragisticsdv']
        },

        'infragisticscore': {
            deps: ['angular', 'jqueryui']
        },

        'jquery': {
            exports: '$'
        },

        'modernizr': {
            exports: 'modernizr'
        },

        'tokenInput': {
            deps: ['jquery']
        }

    },

    deps: ['./boot']
});

Requirejs業力配置

'use strict';

var tests = [];
for (var file in window.__karma__.files) {
  if (/Spec\.js$/.test(file)) {
    tests.push(file);
  }
}

require.config({
  // Karma serves files from '/base'
  baseUrl: '/base/app/scripts',

  paths: {
    angular: '../../bower_components/angular/angular',
    angularAnimate: '../../bower_components/angular-animate/angular-animate',
    angularFoundationTpls: '../../bower_components/angular-foundation/mm-foundation-tpls',
    angularMocks: '../../bower_components/angular-mocks/angular-mocks',
    angularResource: '../../bower_components/angular-resource/angular-resource',
    angularRoute: '../../bower_components/angular-route/angular-route',
    app: 'app',
    domReady: '../../bower_components/domReady/domReady',
    foundation: '../../bower_components/foundation/js/foundation',
    igniteui: '../libs/igniteui/igniteui-angular',
    igniteuidirectives: 'directives/igniteui-directives',
    infragistics: '../libs/infragistics/infragistics',
    infragisticsdv: '../libs/infragistics/infragistics.dv',
    infragisticslob: '../libs/infragistics/infragistics.lob',
    infragisticscore: '../libs/infragistics/infragistics.core',
    jquery: '../../bower_components/jquery/dist/jquery',
    jqueryui: '../../bower_components/jquery-ui/jquery-ui',
    modernizr: '../../bower_components/modernizr/modernizr',
    text: '../../bower_components/requirejs-text/text',
    tokenInput: '../libs/tokeninput/src/jquery.tokeninput',
    underscore: '../../bower_components/underscore/underscore'
  },

  shim: {

    'angular': {
      deps: ['jquery'],
      exports: 'angular'
    },

    'angularAnimate': ['angular'],

    'angularFoundationTpls': {
      deps: ['foundation', 'angular']
    },

    'angularMocks': {
      deps: ['angular'],
      exports: 'angular.mock'
    },

    'angularResource': ['angular'],

    'angularRoute': ['angular'],

    'app':{
        exports: 'app'
    },

    'foundation': {
      deps: ['jquery', 'modernizr'],
      exports: 'Foundation'
    },

    'igniteui': {
      deps: ['infragisticslob']
    },

    'infragisticsdv': {
      deps: ['infragisticscore']
    },

    'infragisticslob': {
      deps: ['infragisticsdv']
    },

    'infragisticscore': {
      deps: ['angular', 'jqueryui']
    },

    'jquery': {
      exports: '$'
    },

    'modernizr': {
      exports: 'modernizr'
    },

    'tokenInput': {
      deps: ['jquery']
    }

  },

  // ask Require.js to load these files (all our tests)
  deps: tests,

  // start test run, once Require.js is done
  callback: window.__karma__.start
});

最后,業力配置

module.exports = function(config) {
  "use strict";
  config.set({

    // base path, that will be used to resolve files and exclude
    basePath: '../',

    // frameworks to use
    frameworks: ['jasmine', 'requirejs'],

    // list of files / patterns to load in the browser
    files: [
      {pattern: 'bower_components/**/*.js', included: false},
      {pattern: 'app/libs/**/*.js', included: false},
      {pattern: 'app/scripts/**/*.js', included: false},
      {pattern: 'test/**/*Spec.js', included: false},
      {pattern: 'app/views/**/*.html', included: false},
      'test/test-main.js'
    ],


    // list of files to exclude
    exclude: [
      'app/scripts/main.js'
    ],


    // test results reporter to use
    // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
    reporters: ['progress'],


    // web server port
    port: 9875,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,


    // Start these browsers, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera
    // - Safari (only Mac)
    // - PhantomJS
    // - IE (only Windows)
    browsers: ['PhantomJS'],


    // If browser does not capture in given timeout [ms], kill it
    captureTimeout: 60000,


    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun: false
  });
};

路線-

define([
    'app',
    'controllers/dashboardController',
    'controllers/inventoryController',
    'controllers/permissionsController',
//    'controllers/serviceController',
    'controllers/detailsController',
    'controllers/treeController',
    'controllers/newInventoryController'
    ], function (app) {
    'use strict';
    return app.config(['$routeProvider', function ($routeProvider) {

        $routeProvider.when('/', {
            redirectTo: '/dashboard'
        });

        $routeProvider.when('/dashboard', {
            templateUrl: '../views/dashboard.html',
            controller: 'dashboardController'
        });

        $routeProvider.when('/inventory', {
            templateUrl: '../views/inventory/inventory.html',
            controller: 'inventoryController'
        });

        $routeProvider.when('/inventory/new', {
            templateUrl: '../views/inventory/newInventory.html',
            controller: 'newInventoryController'
        });

        $routeProvider.when('/permissions', {
            templateUrl: '../views/permissions.html',
            controller: 'permissionsController'
        });

//        $routeProvider.when('/services', {
//            templateUrl: '../views/control/services/services.html',
//            controller: 'serviceController'
//        });

//        $routeProvider.when('/services/details', {
//            templateUrl: '../views/control/services/details/details.html',
//            controller: 'detailsController'
//        });

//        $routeProvider.otherwise({redirectTo: '/'});
    }]);

});

我想念什么?

您是否在app.js中返回了角度模塊引用?

define(['angular'], function(angular){
   var app = angular.module('myapp', []);

   //Other code goes here
   return app;

});

暫無
暫無

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

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