ディレクティブをテストするために単体テストを作成しようとしています。ただし、チェックボックスをクリックしても、モデルは更新されません。
モデルを変更するにはどうすればよいですか?なんとなくまとまりそうにない。
ディレクティブを削除し、スコープ var にバインドされた単純なチェックボックスを使用すると、以下と同じ動作が見られます。(したがって、これは特にディレクティブの問題ではありません)
仕様機能:
describe('validationGroup directive',function(){
var elm,scope;
beforeEach(function(){
//Create a scope
scope.who = {};
scope.who.selfIncluded = true;
scope.who.othersIncluded = false;
//Compile basic form
inject(function($compile) {
elm = angular.element('<div ng-form="testFormName" validation-group="groupName">' +
'<input id="check1" type="checkbox" atleast-one-insured ng-model="who.selfIncluded" ng-change="update()">' +
'<input id="check2" type="checkbox" atleast-one-insured ng-model="who.othersIncluded"ng-change="update()">' +
'</div>');
elm = $compile(elm)(scope);
});
scope.$digest();
});
//Test the basic form we compiled
it("Should manipulate the model",function(){
var cb0 = elm.find("input").eq(0);
expect(scope.who.selfIncluded).toBeTruthy(); // Succeeds
cb0.triggerHandler('click');
scope.$digest(); // probably not necesarry
expect(scope.who.selfIncluded).toBeFalsy(); // Fails
});
});