angularjs - Karma test failing on evaluating app for angular routes -


setting karma tests while using angularjs requirejs. seems setup flags 'typeerror: 'undefined' not object (evaluating 'app.config')' error on routes file.

require 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 karma config

'use strict';  var tests = []; (var file in window.__karma__.files) {   if (/spec\.js$/.test(file)) {     tests.push(file);   } }  require.config({   // karma serves files '/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 load these files (all our tests)   deps: tests,    // start test run, once require.js done   callback: window.__karma__.start }); 

finally karma config

module.exports = function(config) {   "use strict";   config.set({      // base path, used resolve files , exclude     basepath: '../',      // frameworks use     frameworks: ['jasmine', 'requirejs'],      // list of files / patterns load in 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 exclude     exclude: [       'app/scripts/main.js'     ],       // test results reporter use     // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'     reporters: ['progress'],       // web server port     port: 9875,       // enable / disable colors in output (reporters , 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 , executing tests whenever file changes     autowatch: true,       // start these browsers, available:     // - chrome     // - chromecanary     // - firefox     // - opera     // - safari (only mac)     // - phantomjs     // - ie (only windows)     browsers: ['phantomjs'],       // if browser not capture in given timeout [ms], kill     capturetimeout: 60000,       // continuous integration mode     // if true, capture browsers, run tests , exit     singlerun: false   }); }; 

routes -

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: '/'});     }]);  }); 

what missing?

did return angular module reference part of app.js?

define(['angular'], function(angular){    var app = angular.module('myapp', []);     //other code goes here    return app;  }); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -