jeudi 28 janvier 2016

Jasmine Having Trouble Detecting A Checkbox

As part of a larger batch of Jasmine testing, I'm trying to detect whether a box is checked. However, I can't figure out how to get Jasmine to properly detect if a box is checked. Either that, or I can't figure out how to properly check it with jQuery. The following test fails:

it('detects when a checkbox is checked', function() {
  form.affix('input').addClass('checkbox');
  $('.checkbox').prop('checked', true);
  console.log ($('.checkbox').prop('checked'));
  console.log ($('.checkbox').is(':checked'));
  expect($('.checkbox').is(':checked')).toBeTruthy();
});

The Console log shows a true and then a false, which means that there's definitely a property named "checked" with a value of true, but that's not the same as it being :checked.

I tried Googling "use jquery to check a checkbox" and found all kinds of people saying that to check a checkbox, you use the prop() method. Some of those answers were right here on Stack Overflow.

Clearly, I'm doing something wrong. I just need help figuring out what it is. Can anyone help?




Aucun commentaire:

Enregistrer un commentaire