Javascript 带Karma的Angularjs单元测试

Javascript 带Karma的Angularjs单元测试,javascript,angularjs,node.js,unit-testing,karma-runner,Javascript,Angularjs,Node.js,Unit Testing,Karma Runner,测试指令时有一些问题-我们的应用程序试图模块化,因此需要导出角度模块的module.exports module.exports = angular.module('project', []) .config(function ($stateProvider) { $stateProvider .state('alive', { url: '/college', templateUr

测试指令时有一些问题-我们的应用程序试图模块化,因此需要导出角度模块的module.exports

module.exports = angular.module('project', [])

    .config(function ($stateProvider) {
        $stateProvider
            .state('alive', {
                url: '/college',
                templateUrl: 'dashboard.html',
                controller: 'CollegeCtrl',
                authenticate: true
            });
    })
    .factory('College', require('./services/college.service.js'))
    .controller('CollegeCtrl', require('./dashboard/college.controller.js'))
    .directive('collegeTile', require('./dashboard/tile/tile.directive.js'))
    .run(function ($rootScope, SideFactory) {  
        SideFactory.push({                
            'priority': 1,
            'icon': 'fa-th-large'
        });
    });
指令看起来像这样

<div class="thumbnail" ng-click="openProject(college._id)">   
        <span>{{college}}</span>
    </div>
</div>
我在运行karma时出现以下错误:

TypeError: 'undefined' is not a function (evaluating 'expect(true).toBe(true)')
业力形态

module.exports = function (config) {
    config.set({
        // base path, that will be used to resolve files and exclude
        basePath: '',

        // testing framework to use (jasmine/mocha/qunit/...)
        frameworks: ['jasmine', 'chai'],

        // list of files / patterns to load in the browser
        files: [
            'dev/assets/bundle.js',
            'angular-mocks/angular-mocks.js',

            'sample/client/*.html',
            'sample/client/*.spec.js',
            'client/**/*.html',
            'client/**/*.spec.js'
        ],

        preprocessors: {
            'client/**/*.html': ['ng-html2js']
        },

        ngHtml2JsPreprocessor: {
            // strip this from the file path
            stripPrefix: 'client/',
            prependPrefix: 'college/',
            // setting this option will create only a single module that contains templates
            // from all the files, so you can load them all with module('foo')
            moduleName: 'templates'
        },

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

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

        coverageReporter: {
            type: 'html',
            dir: 'coverage'
        },

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

        // web server port
        port: 8080,

        // level of logging: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
        logLevel: 'INFO',

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

        // - IE (only Windows)
        browsers: ['PhantomJS'],

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

请同时发布你的业力配置。业力配置已经添加…谢谢。
module.exports = function (config) {
    config.set({
        // base path, that will be used to resolve files and exclude
        basePath: '',

        // testing framework to use (jasmine/mocha/qunit/...)
        frameworks: ['jasmine', 'chai'],

        // list of files / patterns to load in the browser
        files: [
            'dev/assets/bundle.js',
            'angular-mocks/angular-mocks.js',

            'sample/client/*.html',
            'sample/client/*.spec.js',
            'client/**/*.html',
            'client/**/*.spec.js'
        ],

        preprocessors: {
            'client/**/*.html': ['ng-html2js']
        },

        ngHtml2JsPreprocessor: {
            // strip this from the file path
            stripPrefix: 'client/',
            prependPrefix: 'college/',
            // setting this option will create only a single module that contains templates
            // from all the files, so you can load them all with module('foo')
            moduleName: 'templates'
        },

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

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

        coverageReporter: {
            type: 'html',
            dir: 'coverage'
        },

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

        // web server port
        port: 8080,

        // level of logging: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
        logLevel: 'INFO',

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

        // - IE (only Windows)
        browsers: ['PhantomJS'],

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