2016-06-23 8 views
1

カルマテストをセットアップしようとしていますが、テストを実行する際に問題が発生しています。私は私のテストでは、このカルマコントローラ注入エラー

describe("Test Controller", function() { 
    beforeEach(module('thisApp')); 
    var $controller; 
    var x = 1; 
    beforeEach(inject(function(_$controller_) { 
    $controller = _$controller_; 
    })); 

    it('should work', function() { 
    expect(x).toEqual(1); 
    }); 

}); 

のように書かれているが、私は

Test Controller should work FAILED 
.../node_modules/angular/angular.js:4631:53 
[email protected]/Users/.../node_modules/angular/angular.js:322:24 
[email protected]/Users/.../node_modules/angular/angular.js:4591:12 
[email protected]/Users/.../node_modules/angular/angular.js:4513:30 
[email protected]/Users/.../node_modules/angular-mocks/angular-mocks.js:3067:60 

私のconfファイルは、これらのファイル私はbeforeEachを削除した場合(注入

files: [ 
     'node_modules/angular/angular.js', 
     'node_modules/angular-mocks/angular-mocks.js', 
     'app/app.js', 
     'app/controllers/*.js', 
     'app/test/unit/*.spec.js' 
    ], 

含めされたエラーを取得しています。 ..)それから私のテストが実行され、成功を言うが、それは私がそれを含めるときに私にエラーを与える。

私には何が欠けていますか?

答えて

0

コントローラ注入コードはこのようにする必要があります。

var controller; 
beforeEach(inject(function($rootScope, $controller) { 
     scope = $rootScope.$new(); 
     controller = $controller('TestController', { 
      $scope: scope 
      //Inject more dependencies if you want to 
     }); 
    }));