ネストされたコントローラのユニットテストを作成しようとしていますが、テストで同じ動作をどのように模擬するかわかりません。ネストされたコントローラのユニットテスト
私は2つのコントローラがあります。
function FirstController ($scope) {
$scope.childs = [{
title : 'Hello, earth!'
}];
};
function SecondController ($scope) {
$scope.child.title = $scope.child.title + $scope.$index;
};
そして、私のHTMLで:
<div data-ng-controller="FirstController">
<div data-ng-repeat="child in childs" data-ng-controller="SecondController">
{{ child.title }}
</div>
</div>
そして予想通り、この作品(http://jsfiddle.net/tcayp/1/)
ユニットテスト:
// FirstController
it('Should have childs', function() {
scope = {};
ctrl = new FirstController(scope);
expect(scope.childs.length).toBeGreaterThan(0);
});
// SecondController
it('Should have inherited a child', function() {
scope = {};
ctrl = new SecondController(scope);
expect(scope.child.title).toEqual('Hello, earth!0');
});
をにSecondController-test継承したチェーンをng-repeatからどうやって模倣するのか分かりません。
ありがとう、私はあなたの最初の例を使用するように書き直しました。 – fredrik