私がやっていることが完全に間違っているかどうかはわかりませんが、私はHTML要素のいくつかを定義するために "指示"から "コンポーネント"に切り替えたとき、私は突然私のカルマテスト。ここで私が持っているものです。基本カルマ角1.5コンポーネントテスト
karam.conf.js
...
preprocessors: {
'module-a/module-a.view.html': ['ng-html2js'],
...,
'module-z/module-z.view.html': ['ng-html2js']
},
ngHtml2JsPreprocessor: {
moduleName: 'theTemplates'
},
...
モジュール-a.component.js
(function(){
"use strict";
angular.module('ModuleA').component('moduleAComponent',{
controller: 'ModuleAController as moduleAVm',
templateUrl: 'module-a/module-a.view.html'
});
})();
モジュール-tests.js
は、"use strict";
describe('ModuleA',function(){
beforeEach(module('ModuleA'));
describe('Controller',function(){
...
});
describe('Component',function(){
var element, $rootScope;
beforeEach(module('theTemplates'));
beforeEach(inject([
'$compile','$rootScope',
function($c,$rs) {
$rootScope = $rs;
element = $c('<module-a-component></module-a-component>')($rootScope);
$rootScope.$digest(); // ???
}
]));
it('should have moduleAVm',function(){
expect(element.html()).not.toBe(''); // FAILS HERE
expect(element.html()).toContain('moduleVm'); // FAILS HERE TOO
});
});
});
エラー:
そして、それは私に夜が明け、私の(( 'コントローラ'、機能について説明します。The easiest way to unit-test a component controller is by using the $componentController that is included in ngMock. The advantage of this method is that you do not have to create any DOM elements. The following example shows how to do this for the heroDetail component from above.
Expected '' not to be ''.
コンソールに表示されているエラーを追加できますか?また、このangular.module( 'ModuleA'、[])を使ってみてください。component( 'moduleAComponent' .... –
'module-a/module-aの' angular.module( 'ModuleA'、[]) 'を定義しました。しかし、私はエラーを追加しました。期待している呼び出しで失敗しました。これはelement.html()が空であることを意味します。つまり、それは消化していません(私は思います)。 – westandy