我正在尝试编写单元测试来测试我的指令。但是,当我单击复选框时,它不会更新模型。
我怎样才能让它改变模型?不知何故,它似乎没有绑定。
当我删除指令并仅使用绑定到范围 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
});
});