如何在角度中删除模块未找到的错误?

时间:2015-12-20 05:37:01

标签: angularjs angularjs-directive jasmine karma-runner karma-jasmine

我在这里做了一个简单的控制器示例。

http://plnkr.co/edit/dplJ6sf4kgiwJ5pXu4GE?p=preview

我想测试控制器。我可以在线测试我的控制器

这是我在线测试控制器的代码 http://plnkr.co/edit/xzvhXHPoUdulOM9clOkQ?p=preview

但是当我尝试在我的计算机上运行相同的工作时,我的测试用例就失败了 我收到错误

Module 'app.home' 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.

这是我的电脑代码。 https://dl.dropbox.com/s/no901z41bza7osm/SimpleDemo.zip?dl=0

请运行 npm install 以添加依赖项。

这是我的karma.conf.js文件

// Karma configuration
// Generated on Fri Dec 18 2015 19:53:32 GMT+0530 (IST)

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/jquery/dist/jquery.js' ,
        'bower_components/angular-ui-router/release/angular-ui-router.js' ,
        'bower_components/angular-mocks/angular-mocks.js' ,
        'bower_components/angular-resource/angular-resource.js' ,


        'app/*.js',
        'app/**/*.js',
        'app/**/*.html',
      '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: {
        'app/**/*.html':['ng-html2js']
    },

      ngHtml2JsPreprocessor:{
          moduleName:'templates'

    },

    // 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
  })
}

这是我的代码测试

(function(){

    'use strict'
    describe('http controller test', function() {

        var $rootScope,
            $scope,
            controller,
            $q,
            $httpBackend;

        beforeEach(function() {
            module('app');

            inject(function($injector) {
                $rootScope = $injector.get('$rootScope');
                $scope = $rootScope.$new();
                controller = $injector.get('$controller')('homeCntrl', {
                    $scope: $scope
                })


            })
        })




        describe('Init value', function() {
            it('check name value', function() {
                expect(controller.message).toBeUndefined();
            })

        })

        it('it should be true', function() {
            expect(true).toBeTruthy();

        })
    })


})()

任何更新?如何测试控制器?

更新1

当我这样写的时候它不起作用...检查这些文件

'app/**/*.js',
            'app/*.js',
            'app/home/controller/*.js',
            'app/**/*.html',
           'test/**.js'

整个代码

 files: [

        'bower_components/angular/angular.js' ,
        'bower_components/jquery/dist/jquery.js' ,
        'bower_components/angular-ui-router/release/angular-ui-router.js' ,
        'bower_components/angular-mocks/angular-mocks.js' ,
        'bower_components/angular-resource/angular-resource.js' ,




        'app/**/*.js',
        'app/*.js',
        'app/home/controller/*.js',
        'app/**/*.html',
       'test/**.js'
    ],

但是当我这样写的时候,它完全有效吗?

 files: [

        'bower_components/angular/angular.js' ,
        'bower_components/jquery/dist/jquery.js' ,
        'bower_components/angular-ui-router/release/angular-ui-router.js' ,
        'bower_components/angular-mocks/angular-mocks.js' ,
        'bower_components/angular-resource/angular-resource.js' ,




        'app/home/*.js',
        'app/app.js',
        'app/home/controller/*.js',
        'app/**/*.html',
       'test/**.js'
    ],

1 个答案:

答案 0 :(得分:0)

  

homeCntrl更改为homecntrl

在此行中的route.js中:controller:'homeCntrl as home'