
test( "waitForElement returns a Deferred object", function () {
  	var d = $.waitForElement();
  	equal( String(d.promise), String($.Deferred().promise().promise));
});

module('async', {
	setup: function() {
		window.startTime = +new Date;
		window.fix = $('#qunit-fixture');
		window.idToCheck = 'test-element';
		window.classToCheck = 'test-element';
		window.tagToCheck = 'canvas';
		window.threshold = 600;
	},
	teardown: function() {

	}
})

asyncTest("fails after treshold, if no id is passed in", 1, function() {
	
	$.waitForElement(null, threshold).done(function () {
		ok(false);
		start();
	}).fail(function () {

		ok( ((+new Date) - window.startTime) > threshold - 20 && ((+new Date) - window.startTime) < threshold + 20 );
		start();
	});

});

asyncTest("fails after threshold, if there is no such element", 1, function() {

	$.waitForElement('noelement', threshold).done(function () {
		ok(false);
		start();
	}).fail(function () {
		ok( ((+new Date) - window.startTime) > threshold - 20 && ((+new Date) - window.startTime) < threshold + 20 );
		start();
	});

});

asyncTest("finds an element that already exists", 1, function() {

	fix.append('<div id="' + idToCheck + '"></div>');

	$.waitForElement(idToCheck, threshold).done(function () {
		ok(true);
		start();
	}).fail(function () {
		ok(false);
		start();
	});
});

asyncTest("finds an element that exists after the call but before the threshold", 1, function() {

	setTimeout(function () { 
		fix.append('<div id="' + idToCheck + '"></div>'); 
	}, threshold - 40);

	$.waitForElement(idToCheck, threshold).done(function () {
		ok(true);
		start();
	}).fail(function () {
		ok(false);
		start();
	});
});

asyncTest("fails if the element exists after the threshold", 1, function() {

	setTimeout(function () { 
		fix.append('<div id="' + idToCheck + '"></div>'); 
	}, threshold + 40);

	$.waitForElement(idToCheck, threshold).done(function () {
		ok(false);
		start();
	}).fail(function () {
		ok(true);
		start();
	});
});

asyncTest("finds an element by class name", 1, function() {

	setTimeout(function () { 
		fix.append('<div class="' + classToCheck + '"></div>'); 
	}, threshold - 200);

	$.waitForElement(classToCheck, threshold).done(function () {
		ok(false);
		start();
	}).fail(function () {
		ok(true);
		start();
	});
});

asyncTest("finds an element by tag name", 1, function() {

	setTimeout(function () { 
		fix.append('<' + tagToCheck + '></' + tagToCheck + '>'); 
	}, threshold - 200);

	$.waitForElement(classToCheck, threshold).done(function () {
		ok(false);
		start();
	}).fail(function () {
		ok(true);
		start();
	});
});
@@ -156,16 +156,35 @@
 promise)
+, String(d.promise)
 );%0A%7D);%0A%0A
@@ -200,13 +200,32 @@
 sync
+: passing senarios
 ', %7B%0A
+%0A
 %09set
@@ -368,39 +368,37 @@
 ToCheck = 'test-
-element
+class
 ';%0A%09%09window.tagT
@@ -448,40 +448,13 @@
 ;%0A%09%7D
-,%0A%09teardown: function() %7B%0A%0A%09%7D
+%0A
 %0A%7D)
+;
 %0A%0Aas
@@ -627,17 +627,16 @@
 on () %7B%0A
-%0A
 %09%09ok( ((
@@ -1329,32 +1329,33 @@
 %09%09start();%0A%09%7D);%0A
+%0A
 %7D);%0A%0AasyncTest(%22
@@ -1670,32 +1670,33 @@
 %09%09start();%0A%09%7D);%0A
+%0A
 %7D);%0A%0AasyncTest(%22
@@ -1990,32 +1990,320 @@
 %09%09start();%0A%09%7D);%0A
+%0A%7D);%0A%0A%0Amodule('async: failure (not implemented) senarios', %7B%0A%0A%09setup: function() %7B%0A%09%09window.startTime = +new Date;%0A%09%09window.fix = $('#qunit-fixture');%0A%09%09window.idToCheck = 'test-element';%0A%09%09window.classToCheck = 'test-class';%0A%09%09window.tagToCheck = 'canvas';%0A%09%09window.threshold = 600;%0A%09%7D%0A%0A
 %7D);%0A%0AasyncTest(%22
@@ -2295,36 +2295,44 @@
 );%0A%0AasyncTest(%22f
-inds
+ails finding
  an element by c
@@ -2606,16 +2606,17 @@
 );%0A%09%7D);%0A
+%0A
 %7D);%0A%0Aasy
@@ -2616,36 +2616,44 @@
 );%0A%0AasyncTest(%22f
-inds
+ails finding
  an element by t
@@ -2799,37 +2799,35 @@
 .waitForElement(
-class
+tag
 ToCheck, thresho
@@ -2924,11 +2924,13 @@
 );%0A%09%7D);%0A
+%09%0A
 %7D);

fix tests, rename tests