jqunit: extending jquerys testrunner to all
Written by on March 18th, 2008 in Ajax News.
Michael Grosser has created jqunit which wraps jQuerys testrunner in a way that makes it work with jsUnit, and also useful for libraries other than jQuery.
Here is a full example:
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:
Source: Ajaxian
Original Article: http://feeds.feedburner.com/~r/ajaxian/~3/253715156/jqunit-extending-jquerys-testrunner-to-all