DOM Ready unit tests (but not the supporting fixed code).

This commit is contained in:
Ben Alman 2011-03-31 11:37:48 -04:00
parent 459bd7f89d
commit 368bfc0fe0

View file

@ -685,7 +685,7 @@ test("hover()", function() {
test("mouseover triggers mouseenter", function() {
expect(1);
var count = 0,
elem = jQuery("<a />");
elem.mouseenter(function () {
@ -693,7 +693,7 @@ test("mouseover triggers mouseenter", function() {
});
elem.trigger('mouseover');
equals(count, 1, "make sure mouseover triggers a mouseenter" );
elem.remove();
});
@ -1982,8 +1982,8 @@ test("window resize", function() {
test("focusin bubbles", function() {
expect(5);
var input = jQuery( '<input type="text" />' ).prependTo( "body" ),
var input = jQuery( '<input type="text" />' ).prependTo( "body" ),
order = 0;
jQuery( "body" ).bind( "focusin.focusinBubblesTest", function(){
@ -1996,12 +1996,12 @@ test("focusin bubbles", function() {
// DOM focus method
input[0].focus();
// To make the next focus test work, we need to take focus off the input.
// This will fire another focusin event, so set order to reflect that.
order = 1;
jQuery("#text1")[0].focus();
// jQuery trigger, which calls DOM focus
order = 0;
input.trigger( "focus" );
@ -2010,15 +2010,82 @@ test("focusin bubbles", function() {
jQuery( "body" ).unbind( "focusin.focusinBubblesTest" );
});
/*
test("jQuery(function($) {})", function() {
stop();
jQuery(function($) {
equals(jQuery, $, "ready doesn't provide an event object, instead it provides a reference to the jQuery function, see http://docs.jquery.com/Events/ready#fn");
start();
});
});
(function(){
// This code must be run before DOM ready!
var notYetReady, noEarlyExecution,
order = [],
args = {};
notYetReady = !jQuery.isReady;
test("jQuery.isReady", function() {
expect(2);
equals(notYetReady, true, "jQuery.isReady should not be true before DOM ready");
equals(jQuery.isReady, true, "jQuery.isReady should be true once DOM is ready");
});
// Create an event handler.
function makeHandler( testId ) {
// When returned function is executed, push testId onto `order` array
// to ensure execution order. Also, store event handler arg to ensure
// the correct arg is being passed into the event handler.
return function( arg ) {
order.push(testId);
args[testId] = arg;
};
}
// Bind to the ready event in every possible way.
jQuery(makeHandler("a"));
jQuery(document).ready(makeHandler("b"));
jQuery(document).bind("ready.readytest", makeHandler("c"));
// Do it twice, just to be sure.
jQuery(makeHandler("d"));
jQuery(document).ready(makeHandler("e"));
jQuery(document).bind("ready.readytest", makeHandler("f"));
noEarlyExecution = order.length == 0;
// This assumes that QUnit tests are run on DOM ready!
test("jQuery ready", function() {
expect(11);
ok(noEarlyExecution, "Handlers bound to DOM ready should not execute before DOM ready");
// Ensure execution order.
same(order, ["a", "b", "c", "d", "e", "f"], "All bound DOM ready handlers should have executed in bind-order");
// Ensure handler argument is correct.
equals(args.a, jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery");
equals(args.b, jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery");
ok(args.c instanceof jQuery.Event, "Argument passed to fn in jQuery(document).bind( 'ready', fn ) should be an event object");
order = [];
// Now that the ready event has fired, again bind to the ready event
// in every possible way. These event handlers should execute immediately.
jQuery(makeHandler("g"));
equals(order.pop(), "g", "Event handler should execute immediately");
equals(args.g, jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery");
jQuery(document).ready(makeHandler("h"));
equals(order.pop(), "h", "Event handler should execute immediately");
equals(args.h, jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery");
jQuery(document).bind("ready.readytest", makeHandler("i"));
equals(order.pop(), "i", "Event handler should execute immediately");
ok(args.i instanceof jQuery.Event, "Argument passed to fn in jQuery(document).bind( 'ready', fn ) should be an event object");
// Cleanup.
jQuery(document).unbind("ready.readytest");
});
})();
/*
test("event properties", function() {
stop();
jQuery("#simon1").click(function(event) {