0

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();
});
user4956321
  • 313
  • 1
  • 3
  • 15

1 Answers1

0

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); 
Abhijeet
  • 4,069
  • 1
  • 22
  • 38