如何在angualar js中包含模块以删除未找到的错误模块?

时间:2015-12-20 02:38:02

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

我制作简单的应用程序,只使用角度js显示标题。这是我的代码 http://plnkr.co/edit/dplJ6sf4kgiwJ5pXu4GE?p=preview 它仅显示" home"头 我在计算机中制作相同的代码并安装业力和一切......

我的问题是我无法测试它的控制器。我收到此错误

 Failed to instantiate module app.home due to:
        Error: [$injector:nomod] 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.
        http://errors.angularjs.org/1.4.8/$injector/nomod?p0=app.home
            at /Users/naveenkumar/Documents/ionic_work/SimpleDemo/bower_components/angular/angular.js:68:12

我像那样 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-mocks/angular-mocks.js' ,
        'bower_components/angular-resource/angular-resource.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
  })
}

我做这样的测试

describe('check value',function(){

    var controller,
        $scope,
        $rootScope;
    beforeEach(function(){
        module('app.home')

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

        })

    })



    //it('check   value after click',function(){
    //    controller.clickbtn();
    //    expect(controller.message).toEqual('test');
    //})

    it('check  init',function(){
        expect(controller.message).toBeUndefined();
    })
    it('check fine',function(){
        expect(true).toBeTruthy();
    })


})

0 个答案:

没有答案