AngularJS,Jasmine和问题编写规范测试

时间:2015-07-30 17:47:09

标签: angularjs jasmine

好的,我有一个种子设置,我有Jasmin Running(非常感谢SoEzPz的帮助)。

看起来我的规格不会运行,我尝试并隔离了规格并且没有任何问题但是当我尝试在控制器上写一个时它出错了。

这是控制器。

//This is the about function that is used in the About Module. 
'use strict';
app.controller('AboutController',// jshint ignore:line
    ['$scope',
    function ($scope) {
      $scope.message = 'This is the about page message from the controller';
    }]);

一个非常基本的控制器

这是我的测试

'use strict';

describe('Controller: com/modules/AboutController', function() {

    beforeEach(module('app'));

    var AboutController,
        scope;

        beforeEach(inject(function ($rootScope, $controller) {
            scope = $rootScope.$new();
            AboutController = $controller('AboutController', {
                $scope: scope
            });
        }));
    it('It should show the page message', function () {
        expect(scope.greeting).toEqual("This is the about page message from the controller");
                                       });

    });

规范返回此错误

ReferenceError: module is not defined
    at Suite.<anonymous> (http://localhost:8888/com/modules/about/aboutController_spec.js:5:16)
    at addSpecsToSuite (http://localhost:8888/:801:25)
    at Env.describe (http://localhost:8888/:771:7)
    at jasmineInterface.describe (http://localhost:8888/:3277:18)
    at http://localhost:8888/com/modules/about/aboutController_spec.js:3:1
我错过了什么或者我的规范写错了吗?

我在这里包括ngmock是我的Karma.conf文件

// Karma configuration
// Generated on Tue Jul 28 2015 11:28:22 GMT-0400 (EDT)

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: [
      '../src/lib/js/angular/angular.min.js',
      '../src/lib/js/angular/angular-mocks.js',
      '../src/com/**/*.js',
      '../src/com/**/*_spec.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: ['PhantomJS'],


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

1 个答案:

答案 0 :(得分:1)

这绝对具有欺骗性,在玩了规格之后(认为问题出在实际规格中)我发现测试运行正常,但我的其他规格仍然无法运行,所以我做的就是我回去了并仔细查看了我的karma.conf文件,在查看其他一些示例时,我发现我没有包含足够的bower组件。所以我添加了一些IE资源,cookies等等,并且看到所有测试都通过了。

这是我在文件中为那些可能遇到同样问题的人添加的内容

'bower_components/angular/angular.js',
        'bower_components/angular-route/angular-route.js',
        'bower_components/angular-mocks/angular-mocks.js',
        'bower_components/angular-resource/angular-resource.js',
        'bower_components/angular-cookies/angular-cookies.js',
        'bower_components/angular-sanitize/angular-sanitize.js',
        '../src/com/**/*.js',
        '../src/com/**/*_spec.js'