1

enter image description here我試圖用茉莉花做測試。當我運行這個命令karma start karma.conf.js它給了我這個錯誤。如何在角度中包含模塊?

Chrome 47.0.2526 (Windows 7 0.0.0) Firstcontroller Initialization title should be naveen FAILED 
     Error: [$injector:modulerr] Failed to instantiate module app due to: 
     Error: [$injector:nomod] Module 'app' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the depend 
encies as the second argument. 
     http://errors.angularjs.org/1.4.8/$injector/nomod?p0=app 
      at D:/Webapplication/karmaTest/bower_components/angular/angular.js:68:12 
      at D:/Webapplication/karmaTest/bower_components/angular/angular.js:2005:17 
      at ensure (D:/Webapplication/karmaTest/bower_components/angular/angular.js:1929:38) 
      at module (D:/Webapplication/karmaTest/bower_components/angular/angular.js:2003:14) 
      at D:/Webapplication/karmaTest/bower_components/angular/angular.js:4435:22 
      at forEach (D:/Webapplication/karmaTest/bower_components/angular/angular.js:340:20) 
      at loadModules (D:/Webapplication/karmaTest/bower_components/angular/angular.js:4419:5) 
      at Object.createInjector [as injector] (D:/Webapplication/karmaTest/bower_components/angular/angular.js:4344:11) 
      at Object.workFn (D:/Webapplication/karmaTest/bower_components/angular-mocks/angular-mocks.js:2428:52) 
      at window.inject.angular.mock.inject (D:/Webapplication/karmaTest/bower_components/angular-mocks/angular-mocks.js:2411:37) 

我安裝因緣,因緣,茉莉,果報Chrome啓動..When我運行簡單的測試樣預期(真).toBeTruthy它的工作原理fine.But當我想測試我的控制器。它給我以上的錯誤。

這裏是我的控制器

//(function() { 
// 'use strict'; 
// 
// angular.module('app',[]).controller('FirstController',FirstController); 
// 
// FirstController.$inject=['$scope'] 
// 
// function FirstController($scope){ 
//  $scope.title='naveen'; 
// } 
// 
//})(); 

angular.module('app',[]).controller('FirstController',FirstController); 

FirstController.$inject=['$scope']; 

function FirstController($scope){ 
    $scope.title='naveen'; 
} 

這裏是我的測試spec.js文件

describe('Firstcontroller', function() { 
    var $rootScope, 
     $scope, 
     controller; 

    beforeEach(function() { 
     module('app'); 
     inject(function ($injector) { 
      $rootScope = $injector.get('$rootScope'); 
      $scope=$rootScope.$new(); 
      console.log('==========================') 
      controller=$injector.get('$controller')('FirstController',{$scope:$scope}); 
     }) 
    }) 

    describe('Initialization',function(){ 
     it('title should be naveen',function(){ 
     expect($scope.title).toEqual('naveen') 
     }) 

    }) 
}) 

給它是上面的錯誤,爲什麼? 我包括karma.config文件的包

karma.config文件

// Karma configuration 
// Generated on Tue Dec 08 2015 18:55:16 GMT+0530 (India Standard Time) 

module.exports = function(config) { 
    config.set({ 

    // base path that will be used to resolve all patterns (eg. files, exclude) 
    basePath: '', 


    // frameworks to use 
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter 
    frameworks: ['jasmine'], 


    // list of files/patterns to load in the browser 
    files: [ 
     'bower_components/angular/angular.js', 
     'bower_components/angular-mocks/angular-mocks.js', 
     'bower_components/angular-resource/angular-resource.js', 

     'app/**/.js', 
     'test/**/*.js' 
    ], 


    // list of files to exclude 
    exclude: [ 
    ], 


    // preprocess matching files before serving them to the browser 
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor 
    preprocessors: { 
    }, 


    // test results reporter to use 
    // possible values: 'dots', 'progress' 
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter 
    reporters: ['progress'], 


    // web server port 
    port: 9876, 


    // 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 
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher 
    browsers: ['Chrome'], 


    // Continuous Integration mode 
    // if true, Karma captures browsers, runs the tests and exits 
    singleRun: false, 

    // Concurrency level 
    // how many browser should be started simultanous 
    concurrency: Infinity 
    }) 
} 

更新 我插入應用程序在我的js文件目錄當我改變這個'app/**/.js'「應用程序/ *。js'它工作正常..爲什麼它的作品?

+0

這通常意味着你茉莉測試不能找到你的模塊調用'app',請確保您的'karma.config.js'包含'files'陣列將被加載正確的目錄中。 –

+0

確定我試圖檢查這個 – user944513

+0

請檢查更新的屏幕截圖,我已經加入karma.config.js alll文件file – user944513

回答

0
Module 'app' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. 

在角代碼模塊'apps''app'。 修復拼寫錯誤,它應該工作。