Search code examples
javascripttestingqunit

JS - how to use qunit to test


We have JS API does many things based on the HTML (markup semantics and CSS). We have many codes like this one below:

function initHelpText() {
    $(".helpText, .tooltip, #pageHelp").css("cursor", "hand");
}

Don't worry about what the code does, just an example. Now how I do use qUnit to test, this functionality works. My guess is that I need to set some HTML elements with above classes and some how I need to test this, correct? I understand what qUnit does, but for sure am missing something pretty basic. Could you please help me? Thanks.


Solution

  • This is test for one element

    test('.helpText cursor test',function(){
       var element = $('<div class="helpText"></div>');
       $('body').append(element);
       same($('.helpText').css('cursor'),'hand','Cursor should be hand');
       element.remove();
    });