jqunit: extending jquerys testrunner to all
Date : 2008 03 18 Category : Tech & DevelopmentMichael Grosser has created jQuerys testrunner in a way that makes it work with jsUnit, and also useful for libraries other than jQuery.
Here is a full example:
PLAIN TEXT JAVASCRIPT:var temp = function($) { jqUnit.module('Without local interface'); jqUnit.test('test a', function(){ jqUnit.ok(true); this.ok(true); }); with(jqUnit) { module('With local interface'); test('test b', function(){ ok(true); }); module('Example tests'); test('Real Click vs False Click',function(){ var clicked = false; $('#test-form').click(function(){clicked=true;}); //false click $('#test-form input').click(); ok(!clicked); //real click triggerEvent($('#test-form input').get(0),'click'); ok(clicked); }); test('Waiting',function(){ $('#ajax').load('fixtures/1.html'); expect(1);//expect 1 assertion, here: fails if ajaxStop is never called stop();//pause: so we can wait with setTimeout,setInterval,... $().ajaxStop(function(){setTimeout(function(){ //field is not filled directly after ajaxStop //since DOM traversal comes after stopping to load equals($('#ajax').html(),1);//!reverted jsUnit order start();//resume: make sure its called or tests will halt! })}); }); }}(jQuery);
that produces: