1

テスト ケースの実行中にエラーが発生する

コントローラー: LoginCtrl、テストには空の loginUser オブジェクトが必要/angular/angular.js:4385:15 forEach@D:/XAMPP/htdocs/abc/lib/angular/angular.js:336:11 loadModules@D:/XAMPP/htdocs/abc/lib/angular/angular.js :4346:5 createInjector@D:/XAMPP/htdocs/abc/lib/angular/angular.js:4272:11 workFn@D:/XAMPP/htdocs/abc/lib/angular-mocks/angular-mocks.js:2799 :44 angular.mock.inject@D:/XAMPP/htdocs/abc/lib/angular-mocks/angular-mocks.js:2779:30 @D:/XAMPP/htdocs/abc/tests/getStarted/login/loginCtrl. tests.js:19:5

ログイン テスト コントロール

describe('Controller: LoginCtrl, test', function() {
  var $rootScope, $scope, $q, $state, $httpBackend, $translate, Auth, Navigation;
  var loginCtrl;

  beforeEach(function(){
    module('abc', function ($provide, $translateProvider) {
      $provide.factory('customTranslationLoader', function ($q) {
        return function () {
          var deferred = $q.defer();
          deferred.resolve({});
          return deferred.promise;
        };
      });
      $translateProvider.useLoader('customTranslationLoader');
    });

    inject(function(_$rootScope_, _$controller_, _$state_, _$q_, _Auth_, _Navigation_, _$httpBackend_, _$translate_) {
      $rootScope = _$rootScope_;
      $scope = $rootScope.$new();
      $q = _$q_;
      $httpBackend = _$httpBackend_;
      $translate = _$translate_;
      Auth = _Auth_;
      Navigation = _Navigation_;
      $state = _$state_;

      loginCtrl = _$controller_('LoginCtrl', { $scope: $scope });

      // turn off debug messages
      configurations.debug = false;

      // mock the template requests
      $httpBackend.whenGET('app/default/default.html').respond(200, '');
    });
  });

  it("should have a empty loginUser object", function() {
      expect($scope.loginUser.username).toEqual("");
      expect($scope.loginUser.password).toEqual("");
  });


});

カルマ会議

// Karma configuration


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'],

    plugins: [
     'karma-phantomjs-launcher',
     'karma-jasmine',
     'karma-coverage'
     ],

    // list of files / patterns to load in the browser
    files: [
      //libs
      '../lib/angular/angular.js',
      '../lib/angular-mocks/angular-mocks.js',
      '../lib/angular-ui-router/build/angular-ui-router.min.js',
      '../lib/angular-bootstrap/ui-bootstrap.min.js',
      '../lib/angular-route/angular-route.min.js',
      '../lib/localforage/dist/localforage.min.js',
      '../lib/angular-localforage/dist/angular-localForage.min.js',
      '../lib/angular-translate/angular-translate.min.js',
      '../lib/angular-translate-loader-url/angular-translate-loader-url.min.js',
      '../lib/angular-translate-loader-static-files/angular-translate-loader-static-files.min.js',
      '../lib/angular-translate-loader-partial/angular-translate-loader-partial.min.js',

      //app
      '../app/config/configurations.js',
      '../app/*.js',
      '../app/**/*.js',

      // Tests
      '**/*.tests.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/**/*.js': ['coverage']
    },

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

    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress', 'coverage'],

    // 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: false,


    // 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,


  })
}
4

0 に答える 0