2

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: [
            '../scripts/bower_components/angularjs/angular.js',
            '../scripts/bower_components/angular-mocks/angular-mocks.js',
            '../scripts/app.js',
            '../scripts/11.js',
         
            '../scripts/controllers/*.js',
            '../scripts/directives/*.js',
            '../scripts/services/*.js',
            'controllers/controllersTests.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', 'PhantomJS_custom'],

    customLaunchers: {
      'PhantomJS_custom': {
        base: 'PhantomJS',
        options: {
          windowName: 'my-window',
          settings: {
            webSecurityEnabled: false
          },
        },
        flags: ['--load-images=true'],
        debug: false
      }
    },

    phantomjsLauncher: {
      // Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing phantom)
      exitOnResourceError: true
    },
    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false
  })
}

コントローラーのコードをテストする必要がありますが、正しい結果が表示されません。以下のコード: "slide" array length = 4; しかし、テストでは「toBe(2)」と書くと、次のように表示されます。

PhantomJS 1.9.8 (Linux 0.0.0): 0 の 0 エラーを実行しました (0.035 秒 / 0 秒)

2 を期待しているのに、配列の長さが 4 の場合、なぜ 0 のエラーが表示されるのですか ???

app.controller('mainCtrl',['$scope', function($scope){
  $scope.slide = [1, 2, 3, 4];
}]);
describe('Tests Controllers', function() {
  beforeEach(module('app'));

  var $controller;

  beforeEach(inject(function(_$controller_, $rootScope){
    $controller = _$controller_;

    it('check slides length, it should be 4', function() {
      var $scope = {};
      var controller = $controller('mainCtrl', { $scope: $scope });
      expect($scope.slide.length).toBe(2);
    });
  }));
});
4

1 に答える 1

3

Karma がテストと表示を見つけられない場合Executed 0 of 0 ERROR、この動作につながる最も一般的な理由は次のとおりです。

  • オプションのテスト ファイル/フォルダへのパスが正しくありませkarma.conf.jsfiles:[]
  • itテスト ファイル/フォルダーにスペック (ブロック) がないため、Karma は何も実行できません。あなたの場合のように、仕様がテストファイル内に不適切に配置されている場合にも発生する可能性がありますitbeforeEach、ジャスミンはそれをサポートしていません。アイデアは、それらを同じレベルに置くことです。itspec は、グローバル スコープ内またはdescribeスイート ブロック内に個別に存在できます。
于 2015-09-08T07:38:47.603 に答える