Tuesday, March 18th, 2008
jqunit: extending jquerys testrunner to all
<p>Michael 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:
-
-
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:

Related Content:











correction:
i did not create ‘jQuerys testrunner’ it was created by the jQuery team. Most, if not all, credit for jqUnit goes to Colin Clark (http://groups.google.com/group/jquery-en/msg/b6b7ff05f5f06945)
correction2:
link for jQuery testrunner is not working
image is broken, since of today, since wordpress screwed me and somehow moved/renamed my pictures…
http://pragmatig.files.wordpress.com/2008/03/jqunit.png
maybe it can be fixed when wordpress cache expires…