🌐 AI搜索 & 代理 主页
Skip to content

Commit fcc9a9e

Browse files
stevemaotimmywil
authored andcommitted
Tests: move readywait to an iframe test
Close gh-3576 Fixes gh-3573
1 parent d33bb9c commit fcc9a9e

File tree

5 files changed

+37
-44
lines changed

5 files changed

+37
-44
lines changed

src/deprecated.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ jQuery.fn.extend( {
2323
return arguments.length === 1 ?
2424
this.off( selector, "**" ) :
2525
this.off( types, selector || "**", fn );
26-
},
27-
holdReady: function( hold ) {
28-
if ( hold ) {
29-
jQuery.readyWait++;
30-
} else {
31-
jQuery.ready( true );
32-
}
3326
}
3427
} );
3528

29+
jQuery.holdReady = function( hold ) {
30+
if ( hold ) {
31+
jQuery.readyWait++;
32+
} else {
33+
jQuery.ready( true );
34+
}
35+
};
3636
jQuery.isArray = Array.isArray;
3737
jQuery.parseJSON = JSON.parse;
3838
jQuery.nodeName = nodeName;
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,28 @@
1414
#output { background-color: green }
1515
#expectedOutput { background-color: green }
1616
</style>
17-
<script src="jquery.js"></script>
17+
<script src="../jquery.js"></script>
18+
<script src="./iframeTest.js"></script>
1819

1920
<!-- Load the script loader that uses
2021
jQuery.readyWait -->
21-
<script src="data/readywaitloader.js"></script>
2222

2323
<script type="text/javascript">
24-
jQuery(function() {
25-
// The delayedMessage is defined by
26-
// the readywaitasset.js file, so the
27-
// next line will only work if this DOM
28-
// ready callback is called after readyWait
29-
// has been decremented by readywaitloader.js
30-
// If an error occurs.
31-
jQuery("#output").append(delayedMessage);
32-
});
24+
(function() {
25+
var released = false;
26+
// Hold on jQuery!
27+
jQuery.holdReady( true );
28+
29+
setTimeout( function() {
30+
released = true;
31+
jQuery.holdReady( false );
32+
}, 300 );
33+
34+
jQuery(function() {
35+
jQuery( "#output" ).text( "Ready called, holdReady released: " + released );
36+
startIframeTest( released );
37+
});
38+
})();
3339
</script>
3440
</head>
3541
<body>

test/data/readywaitasset.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/data/readywaitloader.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

test/unit/ready.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ QUnit.module( "ready" );
44
var notYetReady, noEarlyExecution,
55
whenified = jQuery.when( jQuery.ready ),
66
promisified = Promise.resolve( jQuery.ready ),
7+
start = new Date(),
78
order = [],
89
args = {};
910

@@ -147,4 +148,16 @@ QUnit.module( "ready" );
147148
done();
148149
} );
149150
} );
151+
152+
testIframe(
153+
"holdReady test needs to be a standalone test since it deals with DOM ready",
154+
"readywait.html",
155+
function( assert, jQuery, window, document, releaseCalled ) {
156+
assert.expect( 2 );
157+
var now = new Date();
158+
assert.ok( now - start >= 300, "Needs to have waited at least half a second" );
159+
assert.ok( releaseCalled, "The release function was called, which resulted in ready" );
160+
}
161+
);
162+
150163
} )();

0 commit comments

Comments
 (0)