Установка флажка для тестирования qunit

Я начинаю работать с 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

Какие-нибудь мысли?

Спасибо.


person JoshuaMayHome    schedule 11.09.2012    source источник


Ответы (1)


Разве эта строка не должна быть:

 $("#qunit-fixture").append('<input type="checkbox" id="IsOtherEmail" /> ');

то есть «id», а не «имя»?

person Charles Anderson    schedule 11.09.2012
comment
Это сделало это. Я смотрел на это, кажется, 100 раз, и не видел этого. Спасибо. - person JoshuaMayHome; 11.09.2012