0

Few things to know:

  • My app heavily uses
    • jQuery
    • jQuery plugins (jQuery UI, chosen, datatable, etc)
    • Bootstrap

So I am very new to JS unit testing and maybe it will sound very very lame but I have a few questions below:

I have recently started qUnit to test my JS code and have used blanket.js to do code coverage.

Blanket JS output shows code like this as uncovered. I am wondering how/what can I do to get them covered?

    Example 1
    function resetForm(form)    {
      form.reset(); // This line shows not covered
    }

    Example 2
    $('a.staticLink').on('click', function(e)   {
      e.preventDefault();// This line shows not covered
    });

Similarly all generic bootstrap functions like show(), hide() show as not covered.

Even statements that just have a plugin call show as not-covered

       $(".chosen-select").chosen(); //not covered

Any help is greatly appreciated

prgrmr
  • 842
  • 3
  • 14
  • 30

1 Answers1

1

What you have to do is trigger the event manually in your test case. In case of Example 2 something like below

$('a.staticLink').trigger('click');

and write assertions based on what is supposed to happen once that button is clicked. you might consider stubbing external methods using sinon

Pawan
  • 605
  • 1
  • 6
  • 18