Skip to content

Instantly share code, notes, and snippets.

@leobalter
Created January 30, 2014 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leobalter/8702651 to your computer and use it in GitHub Desktop.
Save leobalter/8702651 to your computer and use it in GitHub Desktop.
<html>
<head>
<script type="text/javascript">
setTimeout(function () {
window.custom_$ = {};
}, 2000);
</script>
</head>
<body>
</body>
</html>
<html>
<head>
<script src="http://code.jquery.com/qunit/qunit-1.13.0.js"></script>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<link media="screen" href=".http://code.jquery.com/qunit/qunit-1.13.0.css" rel="stylesheet"/>
<script type="text/javascript">
QUnit.config.autostart = false;
module( "Testing Qunit Bug" );
test( "Testing", function () {
resetFrame().then( function () {
equal( typeof frameWindow.custom_$, "object", "Everything fine" );
});
});
</script>
</head>
<body>
<h1 id="qunit-header">QUnit Bug Test</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<!-- Keep it outside qunit-fixture so that its not reloaded for every test -->
<iframe id="test-frame"></iframe>
<script>
window.frameWindow = $('#test-frame').get(0).contentWindow;
$('#test-frame').load(function() {
if(frameWindow.document.isFrameLoaded || frameWindow.document.URL == 'about:blank') {
return;
}
window.waitTimer = setInterval(function () {
if(!frameWindow.custom_$) { //My lib hasn't loaded yet
return;
}
clearInterval(waitTimer);
setTimeout(function () {
frameWindow.document.isFrameLoaded = true; //It will clean itself after every refresh.
QUnit.start();
}, 1000);
}, 10);
});
function resetFrame() {
//QUnit.stop(); //This is balanced by QUnit.start present after iframe load event when custom_$ is defined.
//QUnit.stop(); //This is balanced by QUnit.start present in then function of the object returned by resetFrame
frameWindw.location.replace("iframe.html");//Intentional Typo here. Due to this I can never know why my test cases are stuck in running state.
return {
then: function (callback) {
var callbackTimer = setInterval(function () {
if(frameWindow.document.isFrameLoaded) {
QUnit.start();
callback();
clearInterval(callbackTimer);
}
}, 1000);
}
}
}
</script>
<div id="qunit-fixture"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment