Kevin Friedheim Kevin Friedheim - 4 months ago 16x
AngularJS Question

testing an angular checkbox using in jasmin

My situation is as follows:


scope: { foo:'=' },
template: '<input type="checkbox" ng-model="foo"/>'

parent controller

$ = false;

jasmine test

var cb = iElement.find('input');

$timeout(function() { // using $timeout to ensure $digest() isn't the issue.

expect(cb.prop('checked')).toBe(true); // passes

expect($; // doesn't pass

My question: why doesn't $ get updated when I issue the prop('checked') even though the DOM does (as I've verified after inspecting it).

Here is a jsbin that roughly demonstrates the problem


After further investigation - it looks like angular will add a click listener when you add an ng-model to something like a checkbox.

So it would seem that the correct method of testing this would be to issue a click event on the DOM object from within the jasmine test.