ジャスミンを使用してコンポーネントの角度を1.5.6単位でテストしようとしています。しかし、私は以下のエラーを受け取り、理由を確かめていません。
例外TypeError:未定義は( 'controller.name' を評価する)オブジェクトではない
成分:
function MainViewerCtrl() {
this.$onInit = function(){
console.log('Component main viewer initialized!');
};
this.name = 'Main Component!';
}
angular.module('ks').component('mainViewer', {
bindings: {
name : '@'
},
controller : MainViewerCtrl,
templateUrl: "mainViewer.html"
});
スペック:
describe('Component : mainViewer', function(){
beforeEach(angular.mock.module('ks'));
describe('with $componentController', function() {
var controller, scope;
beforeEach(inject(function($rootScope, $componentController){
scope = $rootScope.$new();
controller = $componentController('mainViewer',
{$scope:scope},
{name: 'Main Component!'});
}));
it('should have my binding bound', function() {
expect(controller.name).toBeDefined();
expect(controller.name).toBe('Main Component!');
});
});
})。
私は間違っていますか?
あなたはこれをする必要はありません。 '_ $ componentController_'のアンダースコアは、それを挿入して変数名' $ componentController'を使い切らないようにするための規約です。 $ componentControllerが自分自身で定義されていません。 – gonzofish