Trying to simulate a DOM element in my jasmine test
it('Testing radio button change', function () {
simElement = angular.element("<div><input class='my_radio' type='radio' /></div>");
simElement.find('input')[0].checked = true;
var scope = $rootScope.$new();
$compile(simElement)(scope);
scope.$digest();
console.log(simElement.find('input')[0].checked); // expected output: true
myController.changeRadio();
console.log(simElement.find('input')[0].checked); // expected output: false
});
Inside my controller
function changeRadio(){
for(var i = 0; i < angular.element('.simElement').length; i++){
angular.element('simElement')[i].checked = false;
}
}
The console log should display the following results:
true
false
Even though myController.changeRadio
successfully switches the radio button from true to false when the app is running, the jasmine test suite failed. It was discovered that the controller couldn't locate the input element at all. Is there a way to provide the compiled DOM to the controller during testing?