Я начинаю работать с QUnit. У меня есть существующая логика, которая зависит от состояния флажка.
function CheckEmailRequirementSatisfied() {
if (isEdit == "false") {
if ($("#EmailId").val() != "" || $("#IsOtherEmail").is(":checked")) {
$("#EmailRequirementSatisfied").val("1");
} else {
$("#EmailRequirementSatisfied").val("");
}
}
}
У меня есть следующий модуль с настройкой и тестами.
module("CheckEmailRequirementSatisfied", {
setup: function () {
$("#qunit-fixture").append('<input id="EmailId" /> ');
$("#qunit-fixture").append('<input id="EmailRequirementSatisfied" /> ');
$("#qunit-fixture").append('<input type="checkbox" name="IsOtherEmail" /> ');
}
});
test("IsOtherEmail true", function () {
isEdit = "false";
$("#EmailId").val("");
$("#EmailRequirementSatisfied").val("test value");
/*
document.getElementById('IsOtherEmail').checked=true;
$("#IsOtherEmail").prop("checked", true);
$("#IsOtherEmail").attr("checked", "checked");
$("#IsOtherEmail").val(true);
*/
CheckEmailRequirementSatisfied();
ok($("#EmailRequirementSatisfied").val() == "1", "Requirements should be set to 1");
});
Я перепробовал все варианты в блоке комментариев теста, чтобы установить флажок. но он продолжает выходить из строя, говоря, что он не проверен.
Использование https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js и http://code.jquery.com/qunit/qunit-1.10.0.js
Какие-нибудь мысли?
Спасибо.