prgrmr
prgrmr

Reputation: 852

QUnit - testing plugin method calls, generic statements, etc

Few things to know:

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

Upvotes: 0

Views: 92

Answers (1)

Pawan
Pawan

Reputation: 605

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

Upvotes: 1

Related Questions