ネストされたコントローラーの単体テストを作成しようとしていますが、テストで同じ動作をモックする方法がわかりません。
私は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から継承チェーンをモックする方法がわかりません。