4 var notYetReady, noEarlyExecution,
8 notYetReady = !jQuery.isReady;
10 test("jQuery.isReady", function() {
13 equal(notYetReady, true, "jQuery.isReady should not be true before DOM ready");
14 equal(jQuery.isReady, true, "jQuery.isReady should be true once DOM is ready");
17 // Create an event handler.
18 function makeHandler( testId ) {
19 // When returned function is executed, push testId onto `order` array
20 // to ensure execution order. Also, store event handler arg to ensure
21 // the correct arg is being passed into the event handler.
22 return function( arg ) {
28 // Bind to the ready event in every possible way.
29 jQuery(makeHandler("a"));
30 jQuery(document).ready(makeHandler("b"));
31 jQuery(document).on("ready.readytest", makeHandler("c"));
33 // Do it twice, just to be sure.
34 jQuery(makeHandler("d"));
35 jQuery(document).ready(makeHandler("e"));
36 jQuery(document).on("ready.readytest", makeHandler("f"));
38 noEarlyExecution = order.length === 0;
40 // This assumes that QUnit tests are run on DOM ready!
41 test("jQuery ready", function() {
44 ok(noEarlyExecution, "Handlers bound to DOM ready should not execute before DOM ready");
46 // Ensure execution order.
47 deepEqual(order, ["a", "b", "d", "e", "c", "f"], "Bound DOM ready handlers should execute in on-order, but those bound with jQuery(document).on( 'ready', fn ) will always execute last");
49 // Ensure handler argument is correct.
50 equal(args["a"], jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery");
51 equal(args["b"], jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery");
52 ok(args["c"] instanceof jQuery.Event, "Argument passed to fn in jQuery(document).on( 'ready', fn ) should be an event object");
56 // Now that the ready event has fired, again bind to the ready event
57 // in every possible way. These event handlers should execute immediately.
58 jQuery(makeHandler("g"));
59 equal(order.pop(), "g", "Event handler should execute immediately");
60 equal(args["g"], jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery");
62 jQuery(document).ready(makeHandler("h"));
63 equal(order.pop(), "h", "Event handler should execute immediately");
64 equal(args["h"], jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery");
66 jQuery(document).on("ready.readytest", makeHandler("never"));
67 equal(order.length, 0, "Event handler should never execute since DOM ready has already passed");
70 jQuery(document).off("ready.readytest");