Cannot read property 'substring' of undefined issue in Qunit Test case

476 Views Asked by At

In my javascript file below mentioned code is present. But when I run Javascript test cases via Qunit.js and Blanket.js I am getting this error in chrome: "Cannot read property 'substring' of undefined - {}"

if ($("label[for=ReservationInformation]").text().substring(0, 1) != "*") {
            $("label[for=ReservationInformation]").text("*" + $("label[for=ReservationInformation]").text());
        }

I have defined test case as:

test("validationChecker test", 1, function () {
    var div = $('<div>').appendTo("body");
    $('<input>', { id: "ReservationInformation" }).appendTo(div);
    $('<label>', { "for": "ReservationInformation" }).appendTo(div);
    var result = validationChecker(null);
    equal(undefined, result, "passed");
    $("div").remove();
});
1

There are 1 best solutions below

0
David Cardós Uc On

I think that, the problem is in your test case you don't set a text for your label, try changing the label creation by this :

$('<label>', { "for": "ReservationInformation", "text": "Hello" }).appendTo(div);