|
|
Goals
Since i could not find any 'homepage' for jQuerys Unit test suite, i created this project, to host my modifications of it.
The goal is to wrap jQuerys testrunner to use it in all frameworks and make it jsUnit compatible.
If you want to contribute, drop me an email.
Usage
Test Output
- Click one to unfold Test - Results
- Double Click to rerun the selected Test
- test.html?xxx -> run only tests that match /xxx/
Test Suite
Making Test Suites: just link(<source>) to the .js files that hold tests, or call window.location when your first test is done.
Test Case
jqUnit tests often do not need setup or teardown, or the Test Case. But if you need them use them as follows:
//Using TestCase
jqUnit.TestCase.prototype.yep = function(val){ this.ok(val);};
var t = new jqUnit.TestCase('TestCase',function(){
/*setup*/
this.yep(1);
},function(){
/*teardown*/
this.ok(1)
});
//jqUnit is mixed into TestCase, so you can overwrite them & only need 1 with(){}
t.test('part 1',function(){ this.ok(1) });
t.test('part 2',function(){ with(this){ ok(2);yep(3) } });
t.test('part 3',function(){ with(jqUnit){ ok(4); this.yep(5) } });Examples
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);More examples can be found here: jQuery Test Suite Repository Live
Used at
If you run your tests at a public domain, please send me a mail an i will list it here.
Changes
v1.1.1 - refactoring, interface stabel v1.1 - jqUnit is now mixed into TestCase so this will work as expected
