Skip to content

Commit d99268a

Browse files
jrburkejitter
authored andcommitted
Add readyWait tests. Fixes #8145.
Adds tests for the fix to #6781.
1 parent 2862f58 commit d99268a

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

test/data/readywaitasset.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var delayedMessage = "It worked!";

test/data/readywaitloader.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Simple script loader that uses jQuery.readyWait
2+
3+
//Hold on jQuery!
4+
jQuery.readyWait++;
5+
6+
var readyRegExp = /^(complete|loaded)$/;
7+
8+
function assetLoaded( evt ){
9+
var node = evt.currentTarget || evt.srcElement;
10+
if ( evt.type === "load" || readyRegExp.test(node.readyState) ) {
11+
jQuery.ready(true);
12+
}
13+
}
14+
15+
setTimeout( function() {
16+
var script = document.createElement("script");
17+
script.type = "text/javascript";
18+
if ( script.addEventListener ) {
19+
script.addEventListener( "load", assetLoaded, false );
20+
} else {
21+
script.attachEvent( "onreadystatechange", assetLoaded );
22+
}
23+
script.src = "data/readywaitasset.js";
24+
document.getElementsByTagName("head")[0].appendChild(script);
25+
}, 2000 );

test/readywait.html

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<!--
4+
Test for jQuery.readyWait. Needs to be a
5+
standalone test since it deals with DOM
6+
ready.
7+
-->
8+
<head>
9+
<title>
10+
jQuery.readyWait Test
11+
</title>
12+
<style>
13+
div { margin-top: 10px; }
14+
#output { background-color: green }
15+
#expectedOutput { background-color: green }
16+
</style>
17+
<script src="../src/core.js"></script>
18+
<script src="../src/support.js"></script>
19+
<script src="../src/data.js"></script>
20+
<script src="../src/queue.js"></script>
21+
<script src="../src/attributes.js"></script>
22+
<script src="../src/event.js"></script>
23+
<script src="../src/sizzle/sizzle.js"></script>
24+
<script src="../src/sizzle-jquery.js"></script>
25+
<script src="../src/traversing.js"></script>
26+
<script src="../src/manipulation.js"></script>
27+
<script src="../src/css.js"></script>
28+
<script src="../src/ajax.js"></script>
29+
<script src="../src/ajax/jsonp.js"></script>
30+
<script src="../src/ajax/script.js"></script>
31+
<script src="../src/ajax/xhr.js"></script>
32+
<script src="../src/effects.js"></script>
33+
<script src="../src/offset.js"></script>
34+
<script src="../src/dimensions.js"></script>
35+
36+
<!-- Load the script loader that uses
37+
jQuery.readyWait -->
38+
<script src="data/readywaitloader.js"></script>
39+
40+
<script type="text/javascript">
41+
jQuery(function() {
42+
// The delayedMessage is defined by
43+
// the readywaitasset.js file, so the
44+
// next line will only work if this DOM
45+
// ready callback is called after readyWait
46+
// has been decremented by readywaitloader.js
47+
// If an error occurs.
48+
jQuery("#output").append(delayedMessage);
49+
});
50+
</script>
51+
</head>
52+
<body>
53+
<h1>
54+
jQuery.readyWait Test
55+
</h1>
56+
<p>
57+
This is a test page for jQuery.readyWait, that was
58+
added due to this ticket
59+
<a href="http://bugs.jquery.com/ticket/6781">#6781</a>.
60+
</p>
61+
<p>
62+
Test for jQuery.readyWait, which can be used
63+
by plugins and other scripts to indicate something
64+
important to the page is still loading and needs
65+
to block the DOM ready callbacks that are registered
66+
with jQuery.
67+
</p>
68+
<p>
69+
Script loaders are the most likely kind of script
70+
to use jQuery.readyWait, but it could be used by
71+
other things like a script that loads a CSS file
72+
and wants to pause the DOM ready callbacks.
73+
</p>
74+
<p>
75+
<strong>Expected Result</strong>: The text
76+
<span id="expectedOutput">It Worked!</span>
77+
appears below after about <strong>2 seconds.</strong>
78+
</p>
79+
<p>
80+
If there is an error in the console,
81+
or the text does not show up, then the test failed.
82+
</p>
83+
<div id="output"></div>
84+
</body>
85+
</html>

0 commit comments

Comments
 (0)