I'm having this issue regarding jquery. I'm trying to test two paths:
it("should return true when country is valid", function() {
var validCountry = "Germany";
$("#fld_country option:selected").val(validCountry);
expect(isValid("#fld_country")).toBeTruthy();
});
it("should return false when country is invalid", function() {
var invalidCountry = "";
$("#fld_country option:selected").val(invalidCountry);
expect(isValid("#fld_country")).toBeFalsy();
});
validCountry and invalidCountry are options selected from a dropdown list.
This is the isValid function:
function isValid(selector) {
if (selector === "#fld_country option:selected") {
return validator.isSelectedField(selector);
}
else return validator.isFieldEmpty(selector);
}
and this is the isSelectedField:
isSelectedField: function (selector) {
return $.trim($('selector option:selected').html())
Problem is it is failing due to :
validate registration form should return true when country is valid
and
validate registration form should return false when country is invalid FAILED
I don't know what the problem is... any thoughts?