1

The code of my JS file is mentioned below:

 $('#HeaderLink').keypress(function (e) {

     var key = e.which;

     if (key == 13)        
     {

         TravelRegistration.expandSection();
     }
 });

When I run following Javascript Test Case (Qunitjs and Blanket.js), it runs successfully but its not able to call 'expandSection' function. Code coverage only covers only first line of code that is $('#HeaderLink').keypress(function (e) {

Someone please assist how to write test case so that I can call my function.

Code of TEST CASE

test("expandSection test", 1, function () {
    var div = $('<div>').appendTo("body");

    $('<a id="HeaderLink" >').appendTo(div);
    $("#HeaderLink").trigger("keypress" , 13);
    var result = TravelRegistration.expandSection();
    equal(undefined, result, "passed");
    $("div").remove();
});
Vickyexpert
  • 3,147
  • 5
  • 21
  • 34
Raj
  • 183
  • 3
  • 17

1 Answers1

0

You need to create a custom jQuery Event for it:

var e = $.Event("keypress", { which: 13 });
$("#HeaderLink").trigger(e);

See jQuery documentation for it.

Christoph
  • 1,631
  • 8
  • 19