qunittestcase

Convert to QUnit Code


Can Anyone convert this jquery script to Qunit Test code. Since am a beginner, I would like to start from this scratch.

$(document).ready(function(){
jQuery("#but1").bind("click",function(e,data){
    alert(data.name);
});

jQuery("#but1").trigger('click', {name:'Dmy', surname:'My'});
});

Thanks.


Solution

  • Did you try checking the "Cookbook" section of the qunitjs.com site? The event testing is used as a practical example at the following link - http://qunitjs.com/cookbook/#solution-160 - just look at "Practical Example". Here's a copy of the example.

    test( "a test", 1, function() {
      var $body = $( "body" );
    
      $body.on( "click", function() {
        ok( true, "body was clicked!" );
      });
    
      $body.trigger( "click" );
    });