AngularJS Unit testing a link in a directive -
i trying write unit tests test directives. however, when invoke click on checkbox, not update model.
how can make change model? somehow doesn't seem bind.
when remove directive, , use plain checkbox bound scope var, same behavior below found. (so not problem directives)
spec function:
describe('validationgroup directive',function(){ var elm,scope; beforeeach(function(){ //create 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 basic form compiled it("should manipulate model",function(){ var cb0 = elm.find("input").eq(0); expect(scope.who.selfincluded).tobetruthy(); // succeeds cb0.triggerhandler('click'); scope.$digest(); // not necesarry expect(scope.who.selfincluded).tobefalsy(); // fails }); });
as mentioned in comment, angular-scenario has utility called browsertrigger works angular app testing:
browsertrigger(element,'click');
Comments
Post a Comment