Skip to content

Commit d23b6f7

Browse files
committed
test: Clean up documentation and simplify
* Document why the ajax fetch for scripts has to use <script> (or sync XHR). * Remove this hack for the second script, as that one doesn't need it. * Fix typo. * No need for piping into a new Deferred with .then(), using Promise.done() instead.
1 parent cef24b8 commit d23b6f7

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

test/index.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* Implement 'disableNative' option.
3636
*
3737
* Useful for disabling the browsers native JSON api,
38-
* and thus test the plugins methods instead.
38+
* and thus test the plugin's methods instead.
3939
*/
4040
QUnit.config.urlConfig.push({
4141
id: 'disableNative',
@@ -44,30 +44,30 @@
4444
});
4545

4646
if (QUnit.urlParams.disableNative) {
47-
// Unset the native methods in order to test the fallback
48-
// of jquery.json (even in modern browsers).
49-
nativeJSON = window.JSON;
50-
window.JSON = undefined;
47+
nativeJSON = JSON;
48+
JSON = undefined;
5149
}
5250

5351
// Load source
5452
jQuery.ajax({
5553
url: srcPath,
5654
dataType: 'script',
57-
crossDomain: true,
58-
cache: false
55+
cache: false,
56+
// Must use async:false (using XHR) or crossDomain:true (using <script>)
57+
// as otherwise the qunit-phantomjs/bridge.js executes at the wrong time,
58+
// causing a fatal error for JSON undefined (resulting in a timeout).
59+
async: false
5960
}).done(function () {
6061
if (QUnit.urlParams.disableNative) {
61-
window.JSON = nativeJSON;
62+
JSON = nativeJSON;
6263
}
6364

6465
// Load test suite
6566
jQuery.ajax({
6667
url: 'jquery.json.test.js',
6768
dataType: 'script',
68-
crossDomain: true,
6969
cache: false
70-
}).then(function () {
70+
}).done(function () {
7171
QUnit.start();
7272
});
7373
});

0 commit comments

Comments
 (0)