Build: Update test code for compatibility with QUnit 2.x (#4297)

Also, run `grunt npmcopy` to sync the "external" directory with dependencies
from package.json. For example, the Sinon library version didn't match.

Ref gh-4234
Closes gh-4297
This commit is contained in:
abnud1 2019-02-18 19:02:38 +01:00 committed by Michał Gołębiowski-Owczarek
parent da44ff39c2
commit c349818742
38 changed files with 11768 additions and 6224 deletions

View File

@ -1,26 +1,127 @@
QUnit.extend( QUnit.assert, { (function(factory) {
/** // NOTE:
* Check the sequence/order // All techniques except for the "browser globals" fallback will extend the
* // provided QUnit object but return the isolated API methods
* @example test('Example unit test', function(assert) { assert.step(1); setTimeout(function () { assert.step(3); start(); }, 100); assert.step(2); stop(); });
* @param Number expected The excepted step within the test()
* @param String message (optional)
*/
step: function (expected, message) {
// increment internal step counter.
QUnit.config.current.step++;
if (typeof message === "undefined") {
message = "step " + expected;
}
var actual = QUnit.config.current.step;
QUnit.push(QUnit.equiv(actual, expected), actual, expected, message);
}
});
/** // For AMD: Register as an anonymous AMD module with a named dependency on "qunit".
* Reset the step counter for every test() if (typeof define === "function" && define.amd) {
*/ define(["qunit"], factory);
QUnit.testStart(function () { }
QUnit.config.current.step = 0; // For Node.js
}); else if (typeof module !== "undefined" && module && module.exports && typeof require === "function") {
module.exports = factory(require("qunitjs"));
}
// For CommonJS with `exports`, but without `module.exports`, like Rhino
else if (typeof exports !== "undefined" && exports && typeof require === "function") {
var qunit = require("qunitjs");
qunit.extend(exports, factory(qunit));
}
// For browser globals
else {
factory(QUnit);
}
}(function(QUnit) {
/**
* Find an appropriate `Assert` context to `push` results to.
* @param * context - An unknown context, possibly `Assert`, `Test`, or neither
* @private
*/
function _getPushContext(context) {
var pushContext;
if (context && typeof context.push === "function") {
// `context` is an `Assert` context
pushContext = context;
}
else if (context && context.assert && typeof context.assert.push === "function") {
// `context` is a `Test` context
pushContext = context.assert;
}
else if (
QUnit && QUnit.config && QUnit.config.current && QUnit.config.current.assert &&
typeof QUnit.config.current.assert.push === "function"
) {
// `context` is an unknown context but we can find the `Assert` context via QUnit
pushContext = QUnit.config.current.assert;
}
else if (QUnit && typeof QUnit.push === "function") {
pushContext = QUnit.push;
}
else {
throw new Error("Could not find the QUnit `Assert` context to push results");
}
return pushContext;
}
/**
* Find an appropriate `Test` context to `push` results to.
* @param * context - An unknown context, possibly `Assert`, `Test`, or neither
* @private
*/
function _getTestContext(context) {
var testContext;
if (context && typeof context.push === "function" && context.test) {
// `context` is an `Assert` context
testContext = context.test;
}
else if (context && context.assert && typeof context.assert.push === "function") {
// `context` is a `Test` context
testContext = context;
}
else if (
QUnit && QUnit.config && QUnit.config.current && QUnit.config.current.assert &&
typeof QUnit.config.current.assert.push === "function"
) {
// `context` is an unknown context but we can find the `Test` context via QUnit
testContext = QUnit.config.current;
}
else {
throw new Error("Could not find the QUnit `Test` context to maintain state");
}
return testContext;
}
var api = {
/**
* Check the sequence/order
*
* @example test('Example unit test', function(assert) { assert.step(1); setTimeout(function () { assert.step(3); start(); }, 100); assert.step(2); stop(); });
* @param Number expected The excepted step within the test()
* @param String message (optional)
*/
step: function(expected, message) {
var actual,
pushContext = _getPushContext(this),
testContext = _getTestContext(this);
if (typeof message === "undefined") {
message = "step " + expected;
}
// If this is the first time that `assert.step` has been called for the
// current test, set its initial `step` counter to `0`
if (typeof testContext.step === "undefined") {
testContext.step = 0;
}
// Increment internal step counter
actual = ++testContext.step;
pushContext.push(QUnit.equiv(actual, expected), actual, expected, message);
}
};
QUnit.extend(QUnit.assert, api);
return api;
}));

View File

@ -1,21 +0,0 @@
Copyright 2013 jQuery Foundation and other contributors
http://jquery.com/
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,7 +1,6 @@
/** vim: et:ts=4:sw=4:sts=4 /** vim: et:ts=4:sw=4:sts=4
* @license RequireJS 2.1.22 Copyright (c) 2010-2015, The Dojo Foundation All Rights Reserved. * @license RequireJS 2.3.5 Copyright jQuery Foundation and other contributors.
* Available via the MIT or new BSD license. * Released under MIT license, https://github.com/requirejs/requirejs/blob/master/LICENSE
* see: http://github.com/jrburke/requirejs for details
*/ */
//Not using strict: uneven strict support in browsers, #392, and causes //Not using strict: uneven strict support in browsers, #392, and causes
//problems with requirejs.exec()/transpiler plugins that may not be strict. //problems with requirejs.exec()/transpiler plugins that may not be strict.
@ -9,18 +8,17 @@
/*global window, navigator, document, importScripts, setTimeout, opera */ /*global window, navigator, document, importScripts, setTimeout, opera */
var requirejs, require, define; var requirejs, require, define;
(function (global) { (function (global, setTimeout) {
var req, s, head, baseElement, dataMain, src, var req, s, head, baseElement, dataMain, src,
interactiveScript, currentlyAddingScript, mainScript, subPath, interactiveScript, currentlyAddingScript, mainScript, subPath,
version = '2.1.22', version = '2.3.5',
commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg, commentRegExp = /\/\*[\s\S]*?\*\/|([^:"'=]|^)\/\/.*$/mg,
cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g, cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
jsSuffixRegExp = /\.js$/, jsSuffixRegExp = /\.js$/,
currDirRegExp = /^\.\//, currDirRegExp = /^\.\//,
op = Object.prototype, op = Object.prototype,
ostring = op.toString, ostring = op.toString,
hasOwn = op.hasOwnProperty, hasOwn = op.hasOwnProperty,
ap = Array.prototype,
isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document), isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document),
isWebWorker = !isBrowser && typeof importScripts !== 'undefined', isWebWorker = !isBrowser && typeof importScripts !== 'undefined',
//PS3 indicates loaded and complete, but need to wait for complete //PS3 indicates loaded and complete, but need to wait for complete
@ -37,6 +35,11 @@ var requirejs, require, define;
globalDefQueue = [], globalDefQueue = [],
useInteractive = false; useInteractive = false;
//Could match something like ')//comment', do not lose the prefix to comment.
function commentReplace(match, singlePrefix) {
return singlePrefix || '';
}
function isFunction(it) { function isFunction(it) {
return ostring.call(it) === '[object Function]'; return ostring.call(it) === '[object Function]';
} }
@ -437,7 +440,9 @@ var requirejs, require, define;
//Account for relative paths if there is a base name. //Account for relative paths if there is a base name.
if (name) { if (name) {
if (prefix) { if (prefix) {
if (pluginModule && pluginModule.normalize) { if (isNormalized) {
normalizedName = name;
} else if (pluginModule && pluginModule.normalize) {
//Plugin is loaded, use its normalize method. //Plugin is loaded, use its normalize method.
normalizedName = pluginModule.normalize(name, function (name) { normalizedName = pluginModule.normalize(name, function (name) {
return normalize(name, parentName, applyMap); return normalize(name, parentName, applyMap);
@ -861,10 +866,21 @@ var requirejs, require, define;
if (this.depCount < 1 && !this.defined) { if (this.depCount < 1 && !this.defined) {
if (isFunction(factory)) { if (isFunction(factory)) {
try { //If there is an error listener, favor passing
//to that instead of throwing an error. However,
//only do it for define()'d modules. require
//errbacks should not be called for failures in
//their callbacks (#699). However if a global
//onError is set, use that.
if ((this.events.error && this.map.isDefine) ||
req.onError !== defaultOnError) {
try {
exports = context.execCb(id, factory, depExports, exports);
} catch (e) {
err = e;
}
} else {
exports = context.execCb(id, factory, depExports, exports); exports = context.execCb(id, factory, depExports, exports);
} catch (e) {
err = e;
} }
// Favor return value over exports. If node/cjs in play, // Favor return value over exports. If node/cjs in play,
@ -881,30 +897,12 @@ var requirejs, require, define;
} }
if (err) { if (err) {
// If there is an error listener, favor passing err.requireMap = this.map;
// to that instead of throwing an error. However, err.requireModules = this.map.isDefine ? [this.map.id] : null;
// only do it for define()'d modules. require err.requireType = this.map.isDefine ? 'define' : 'require';
// errbacks should not be called for failures in return onError((this.error = err));
// their callbacks (#699). However if a global
// onError is set, use that.
if ((this.events.error && this.map.isDefine) ||
req.onError !== defaultOnError) {
err.requireMap = this.map;
err.requireModules = this.map.isDefine ? [this.map.id] : null;
err.requireType = this.map.isDefine ? 'define' : 'require';
return onError((this.error = err));
} else if (typeof console !== 'undefined' &&
console.error) {
// Log the error for debugging. If promises could be
// used, this would be different, but making do.
console.error(err);
} else {
// Do not want to completely lose the error. While this
// will mess up processing and lead to similar results
// as bug 1440, it at least surfaces the error.
req.onError(err);
}
} }
} else { } else {
//Just a literal value //Just a literal value
exports = factory; exports = factory;
@ -976,7 +974,8 @@ var requirejs, require, define;
//prefix and name should already be normalized, no need //prefix and name should already be normalized, no need
//for applying map config again either. //for applying map config again either.
normalizedMap = makeModuleMap(map.prefix + '!' + name, normalizedMap = makeModuleMap(map.prefix + '!' + name,
this.map.parentMap); this.map.parentMap,
true);
on(normalizedMap, on(normalizedMap,
'defined', bind(this, function (value) { 'defined', bind(this, function (value) {
this.map.normalizedMap = normalizedMap; this.map.normalizedMap = normalizedMap;
@ -1288,6 +1287,14 @@ var requirejs, require, define;
} }
} }
// Convert old style urlArgs string to a function.
if (typeof cfg.urlArgs === 'string') {
var urlArgs = cfg.urlArgs;
cfg.urlArgs = function(id, url) {
return (url.indexOf('?') === -1 ? '?' : '&') + urlArgs;
};
}
//Save off the paths since they require special processing, //Save off the paths since they require special processing,
//they are additive. //they are additive.
var shim = config.shim, var shim = config.shim,
@ -1664,13 +1671,12 @@ var requirejs, require, define;
//Join the path parts together, then figure out if baseUrl is needed. //Join the path parts together, then figure out if baseUrl is needed.
url = syms.join('/'); url = syms.join('/');
url += (ext || (/^data\:|\?/.test(url) || skipExt ? '' : '.js')); url += (ext || (/^data\:|^blob\:|\?/.test(url) || skipExt ? '' : '.js'));
url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url; url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url;
} }
return config.urlArgs ? url + return config.urlArgs && !/^blob\:/.test(url) ?
((url.indexOf('?') === -1 ? '?' : '&') + url + config.urlArgs(moduleName, url) : url;
config.urlArgs) : url;
}, },
//Delegates to req.load. Broken out as a separate function to //Delegates to req.load. Broken out as a separate function to
@ -1724,8 +1730,8 @@ var requirejs, require, define;
each(value.depMaps, function(depMap) { each(value.depMaps, function(depMap) {
if (depMap.id === data.id) { if (depMap.id === data.id) {
parents.push(key); parents.push(key);
return true;
} }
return true;
}); });
} }
}); });
@ -1891,9 +1897,6 @@ var requirejs, require, define;
if (isBrowser) { if (isBrowser) {
//In the browser so use a script tag //In the browser so use a script tag
node = req.createNode(config, moduleName, url); node = req.createNode(config, moduleName, url);
if (config.onNodeCreated) {
config.onNodeCreated(node, config, moduleName, url);
}
node.setAttribute('data-requirecontext', context.contextName); node.setAttribute('data-requirecontext', context.contextName);
node.setAttribute('data-requiremodule', moduleName); node.setAttribute('data-requiremodule', moduleName);
@ -1909,11 +1912,11 @@ var requirejs, require, define;
if (node.attachEvent && if (node.attachEvent &&
//Check if node.attachEvent is artificially added by custom script or //Check if node.attachEvent is artificially added by custom script or
//natively supported by browser //natively supported by browser
//read https://github.com/jrburke/requirejs/issues/187 //read https://github.com/requirejs/requirejs/issues/187
//if we can NOT find [native code] then it must NOT natively supported. //if we can NOT find [native code] then it must NOT natively supported.
//in IE8, node.attachEvent does not have toString() //in IE8, node.attachEvent does not have toString()
//Note the test for "[native code" with no closing brace, see: //Note the test for "[native code" with no closing brace, see:
//https://github.com/jrburke/requirejs/issues/273 //https://github.com/requirejs/requirejs/issues/273
!(node.attachEvent.toString && node.attachEvent.toString().indexOf('[native code') < 0) && !(node.attachEvent.toString && node.attachEvent.toString().indexOf('[native code') < 0) &&
!isOpera) { !isOpera) {
//Probably IE. IE (at least 6-8) do not fire //Probably IE. IE (at least 6-8) do not fire
@ -1941,6 +1944,12 @@ var requirejs, require, define;
} }
node.src = url; node.src = url;
//Calling onNodeCreated after all properties on the node have been
//set, but before it is placed in the DOM.
if (config.onNodeCreated) {
config.onNodeCreated(node, config, moduleName, url);
}
//For some cache cases in IE 6-8, the script executes before the end //For some cache cases in IE 6-8, the script executes before the end
//of the appendChild execution, so to tie an anonymous define //of the appendChild execution, so to tie an anonymous define
//call to the module name (which is stored on the node), hold on //call to the module name (which is stored on the node), hold on
@ -1962,6 +1971,11 @@ var requirejs, require, define;
//are in play, the expectation is that a build has been done so //are in play, the expectation is that a build has been done so
//that only one script needs to be loaded anyway. This may need //that only one script needs to be loaded anyway. This may need
//to be reevaluated if other use cases become common. //to be reevaluated if other use cases become common.
// Post a task to the event loop to work around a bug in WebKit
// where the worker gets garbage-collected after calling
// importScripts(): https://webkit.org/b/153317
setTimeout(function() {}, 0);
importScripts(url); importScripts(url);
//Account for anonymous modules //Account for anonymous modules
@ -2007,8 +2021,10 @@ var requirejs, require, define;
//Preserve dataMain in case it is a path (i.e. contains '?') //Preserve dataMain in case it is a path (i.e. contains '?')
mainScript = dataMain; mainScript = dataMain;
//Set final baseUrl if there is not already an explicit one. //Set final baseUrl if there is not already an explicit one,
if (!cfg.baseUrl) { //but only do so if the data-main value is not a loader plugin
//module ID.
if (!cfg.baseUrl && mainScript.indexOf('!') === -1) {
//Pull off the directory of data-main for use as the //Pull off the directory of data-main for use as the
//baseUrl. //baseUrl.
src = mainScript.split('/'); src = mainScript.split('/');
@ -2069,7 +2085,7 @@ var requirejs, require, define;
if (callback.length) { if (callback.length) {
callback callback
.toString() .toString()
.replace(commentRegExp, '') .replace(commentRegExp, commentReplace)
.replace(cjsRequireRegExp, function (match, dep) { .replace(cjsRequireRegExp, function (match, dep) {
deps.push(dep); deps.push(dep);
}); });
@ -2126,4 +2142,4 @@ var requirejs, require, define;
//Set up with config info. //Set up with config info.
req(cfg); req(cfg);
}(this)); }(this, (typeof setTimeout === 'undefined' ? undefined : setTimeout)));

View File

@ -1,6 +1,6 @@
(The BSD License) (The BSD License)
Copyright (c) 2010-2014, Christian Johansen, christian@cjohansen.no Copyright (c) 2010-2017, Christian Johansen, christian@cjohansen.no
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,

17230
external/sinon/sinon.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,10 +1,10 @@
<script> <script>
<!-- <!--
ok( true, "script within html comments executed" ); QUnit.assert.ok( true, "script within html comments executed" );
--> -->
</script> </script>
<script> <script>
<![CDATA[ <![CDATA[
ok( true, "script within CDATA executed" ); QUnit.assert.ok( true, "script within CDATA executed" );
]]> ]]>
</script> </script>

View File

@ -1 +1 @@
window.ok( true, "evaluated: inner module with src" ); QUnit.assert.ok( true, "evaluated: inner module with src" );

View File

@ -16,7 +16,7 @@ class MockServer {
header( 'Content-type: text/javascript' ); header( 'Content-type: text/javascript' );
} else { } else {
header( 'Content-type: text/html' ); header( 'Content-type: text/html' );
echo 'ERROR <script>ok( true, "mock executed" );</script>'; echo 'ERROR <script>QUnit.assert.ok( true, "mock executed" );</script>';
} }
} }
@ -54,7 +54,7 @@ class MockServer {
} else { } else {
header( 'Content-type: text/html' ); header( 'Content-type: text/html' );
} }
echo 'ok( true, "mock executed" );'; echo 'QUnit.assert.ok( true, "mock executed" );';
} }
// Used to be in test.js, but was renamed to testbar.php // Used to be in test.js, but was renamed to testbar.php
@ -62,7 +62,7 @@ class MockServer {
protected function testbar( $req ) { protected function testbar( $req ) {
echo 'this.testBar = "bar"; echo 'this.testBar = "bar";
jQuery("#ap").html("bar"); jQuery("#ap").html("bar");
ok( true, "mock executed");'; QUnit.assert.ok( true, "mock executed");';
} }
protected function json( $req ) { protected function json( $req ) {

View File

@ -1 +1 @@
window.ok( true, "evaluated: module with src" ); QUnit.assert.ok( true, "evaluated: module with src" );

View File

@ -1 +1 @@
ERROR <script type="text/javascript">ok( true, "name.html retrieved" );</script> ERROR <script type="text/javascript">QUnit.assert.ok( true, "name.html retrieved" );</script>

View File

@ -1,7 +1,7 @@
html text<br/> html text<br/>
<script type="text/javascript">/* <![CDATA[ */ <script type="text/javascript">/* <![CDATA[ */
testFoo = "foo"; jQuery('#foo').html('foo'); testFoo = "foo"; jQuery('#foo').html('foo');
ok( true, "test.include.html executed" ); QUnit.assert.ok( true, "test.include.html executed" );
/* ]]> */</script> /* ]]> */</script>
<script src="{{baseURL}}mock.php?action=testbar"></script> <script src="{{baseURL}}mock.php?action=testbar"></script>
blabla blabla

View File

@ -1,5 +1,5 @@
<script type="text/javascript"> <script type="text/javascript">
var testFoo = "foo"; var testFoo = "foo";
jQuery('#foo').html('foo'); jQuery('#foo').html('foo');
ok( true, "test2.html executed" ); QUnit.assert.ok( true, "test2.html executed" );
</script> </script>

View File

@ -48,7 +48,7 @@ this.q = function() {
* @param {(String|Node)=document} context - Selector context * @param {(String|Node)=document} context - Selector context
* @example match("Check for something", "p", ["foo", "bar"]); * @example match("Check for something", "p", ["foo", "bar"]);
*/ */
function match( message, selector, expectedIds, context ) { function match( message, selector, expectedIds, context, assert ) {
var f = jQuery( selector, context ).get(), var f = jQuery( selector, context ).get(),
s = "", s = "",
i = 0; i = 0;
@ -57,7 +57,7 @@ function match( message, selector, expectedIds, context ) {
s += ( s && "," ) + "\"" + f[ i ].id + "\""; s += ( s && "," ) + "\"" + f[ i ].id + "\"";
} }
this.deepEqual( f, q.apply( q, expectedIds ), message + " (" + selector + ")" ); assert.deepEqual( f, q.apply( q, expectedIds ), message + " (" + selector + ")" );
} }
/** /**
@ -69,7 +69,7 @@ function match( message, selector, expectedIds, context ) {
* @example t("Check for something", "p", ["foo", "bar"]); * @example t("Check for something", "p", ["foo", "bar"]);
*/ */
QUnit.assert.t = function( message, selector, expectedIds ) { QUnit.assert.t = function( message, selector, expectedIds ) {
match( message, selector, expectedIds, undefined ); match( message, selector, expectedIds, undefined, QUnit.assert );
}; };
/** /**
@ -81,7 +81,7 @@ QUnit.assert.t = function( message, selector, expectedIds ) {
* @example selectInFixture("Check for something", "p", ["foo", "bar"]); * @example selectInFixture("Check for something", "p", ["foo", "bar"]);
*/ */
QUnit.assert.selectInFixture = function( message, selector, expectedIds ) { QUnit.assert.selectInFixture = function( message, selector, expectedIds ) {
match( message, selector, expectedIds, "#qunit-fixture" ); match( message, selector, expectedIds, "#qunit-fixture", QUnit.assert );
}; };
this.createDashboardXML = function() { this.createDashboardXML = function() {
@ -174,7 +174,8 @@ function url( value ) {
// Ajax testing helper // Ajax testing helper
this.ajaxTest = function( title, expect, options ) { this.ajaxTest = function( title, expect, options ) {
QUnit.test( title, expect, function( assert ) { QUnit.test( title, function( assert ) {
assert.expect( expect );
var requestOptions; var requestOptions;
if ( typeof options === "function" ) { if ( typeof options === "function" ) {

View File

@ -13,8 +13,7 @@ var oldCacheLength = 0,
* QUnit configuration * QUnit configuration
*/ */
// Max time for stop() and asyncTest() until it aborts test // Max time for done() to fire in an async test.
// and start()'s the next test.
QUnit.config.testTimeout = 60e3; // 1 minute QUnit.config.testTimeout = 60e3; // 1 minute
// Enforce an "expect" argument or expect() call in all test bodies. // Enforce an "expect" argument or expect() call in all test bodies.

View File

@ -21,7 +21,7 @@ var mocks = {
resp.writeHead( 200, { "content-type": "text/javascript" } ); resp.writeHead( 200, { "content-type": "text/javascript" } );
} else { } else {
resp.writeHead( 200, { "content-type": "text/html" } ); resp.writeHead( 200, { "content-type": "text/html" } );
resp.end( "ERROR <script>ok( true, \"mock executed\" );</script>" ); resp.end( "ERROR <script>QUnit.assert.ok( true, \"mock executed\" );</script>" );
} }
}, wait ); }, wait );
}, },
@ -67,14 +67,14 @@ var mocks = {
} else { } else {
resp.writeHead( 200, { "content-type": "text/html" } ); resp.writeHead( 200, { "content-type": "text/html" } );
} }
resp.end( "ok( true, \"mock executed\" );" ); resp.end( "QUnit.assert.ok( true, \"mock executed\" );" );
}, },
testbar: function( req, resp ) { testbar: function( req, resp ) {
resp.writeHead( 200 ); resp.writeHead( 200 );
resp.end( resp.end(
"this.testBar = 'bar'; " + "this.testBar = 'bar'; " +
"jQuery('#ap').html('bar'); " + "jQuery('#ap').html('bar'); " +
"ok( true, 'mock executed');" "QUnit.assert.ok( true, 'mock executed');"
); );
}, },
json: function( req, resp ) { json: function( req, resp ) {

View File

@ -1,5 +1,5 @@
QUnit.module( "ajax", { QUnit.module( "ajax", {
teardown: function() { afterEach: function() {
jQuery( document ).off( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess" ); jQuery( document ).off( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess" );
moduleTeardown.apply( this, arguments ); moduleTeardown.apply( this, arguments );
} }
@ -221,9 +221,11 @@ QUnit.module( "ajax", {
}; };
} ); } );
QUnit.asyncTest( "jQuery.ajax() - retry with jQuery.ajax( this )", 2, function( assert ) { QUnit.test( "jQuery.ajax() - retry with jQuery.ajax( this )", function( assert ) {
assert.expect( 2 );
var previousUrl, var previousUrl,
firstTime = true; firstTime = true,
done = assert.async();
jQuery.ajax( { jQuery.ajax( {
url: url( "mock.php?action=error" ), url: url( "mock.php?action=error" ),
error: function() { error: function() {
@ -239,7 +241,7 @@ QUnit.module( "ajax", {
previousUrl = this.url; previousUrl = this.url;
} else { } else {
assert.strictEqual( this.url, previousUrl, "url parameters are not re-appended" ); assert.strictEqual( this.url, previousUrl, "url parameters are not re-appended" );
QUnit.start(); done();
return false; return false;
} }
}, },
@ -856,7 +858,9 @@ QUnit.module( "ajax", {
}; };
} ); } );
QUnit.asyncTest( "jQuery.ajax(), jQuery.get[Script|JSON](), jQuery.post(), pass-through request object", 8, function( assert ) { QUnit.test( "jQuery.ajax(), jQuery.get[Script|JSON](), jQuery.post(), pass-through request object", function( assert ) {
assert.expect( 8 );
var done = assert.async();
var target = "name.html", var target = "name.html",
successCount = 0, successCount = 0,
errorCount = 0, errorCount = 0,
@ -872,7 +876,7 @@ QUnit.module( "ajax", {
assert.equal( successCount, 5, "Check all ajax calls successful" ); assert.equal( successCount, 5, "Check all ajax calls successful" );
assert.equal( errorCount, 0, "Check no ajax errors (status" + errorEx + ")" ); assert.equal( errorCount, 0, "Check no ajax errors (status" + errorEx + ")" );
jQuery( document ).off( "ajaxError.passthru" ); jQuery( document ).off( "ajaxError.passthru" );
QUnit.start(); done();
} ); } );
Globals.register( "testBar" ); Globals.register( "testBar" );
@ -1376,7 +1380,9 @@ QUnit.module( "ajax", {
}, },
function( type, url ) { function( type, url ) {
url = baseURL + url + "&ts=" + ifModifiedNow++; url = baseURL + url + "&ts=" + ifModifiedNow++;
QUnit.asyncTest( "jQuery.ajax() - " + type + " support" + label, 4, function( assert ) { QUnit.test( "jQuery.ajax() - " + type + " support" + label, function( assert ) {
assert.expect( 4 );
var done = assert.async();
jQuery.ajax( { jQuery.ajax( {
url: url, url: url,
ifModified: true, ifModified: true,
@ -1393,7 +1399,7 @@ QUnit.module( "ajax", {
assert.equal( data, null, "no response body is given" ); assert.equal( data, null, "no response body is given" );
}, },
complete: function() { complete: function() {
QUnit.start(); done();
} }
} ); } );
} }
@ -1434,24 +1440,27 @@ QUnit.module( "ajax", {
}; };
} ); } );
QUnit.asyncTest( "jQuery.ajax() - statusText", 3, function( assert ) { QUnit.test( "jQuery.ajax() - statusText", function( assert ) {
assert.expect( 3 );
var done = assert.async();
jQuery.ajax( url( "mock.php?action=status&code=200&text=Hello" ) ).done( function( _, statusText, jqXHR ) { jQuery.ajax( url( "mock.php?action=status&code=200&text=Hello" ) ).done( function( _, statusText, jqXHR ) {
assert.strictEqual( statusText, "success", "callback status text ok for success" ); assert.strictEqual( statusText, "success", "callback status text ok for success" );
assert.ok( jqXHR.statusText === "Hello" || jqXHR.statusText === "OK", "jqXHR status text ok for success (" + jqXHR.statusText + ")" ); assert.ok( jqXHR.statusText === "Hello" || jqXHR.statusText === "OK", "jqXHR status text ok for success (" + jqXHR.statusText + ")" );
jQuery.ajax( url( "mock.php?action=status&code=404&text=World" ) ).fail( function( jqXHR, statusText ) { jQuery.ajax( url( "mock.php?action=status&code=404&text=World" ) ).fail( function( jqXHR, statusText ) {
assert.strictEqual( statusText, "error", "callback status text ok for error" ); assert.strictEqual( statusText, "error", "callback status text ok for error" );
QUnit.start(); done();
} ); } );
} ); } );
} ); } );
QUnit.asyncTest( "jQuery.ajax() - statusCode", 20, function( assert ) { QUnit.test( "jQuery.ajax() - statusCode", function( assert ) {
assert.expect( 20 );
var count = 12; var done = assert.async(),
count = 12;
function countComplete() { function countComplete() {
if ( !--count ) { if ( !--count ) {
QUnit.start(); done();
} }
} }
@ -1853,12 +1862,14 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} ); } );
} }
QUnit.asyncTest( "#11743 - jQuery.ajax() - script, throws exception", 1, function( assert ) { QUnit.test( "#11743 - jQuery.ajax() - script, throws exception", function( assert ) {
assert.expect( 1 );
var done = assert.async();
var onerror = window.onerror; var onerror = window.onerror;
window.onerror = function() { window.onerror = function() {
assert.ok( true, "Exception thrown" ); assert.ok( true, "Exception thrown" );
window.onerror = onerror; window.onerror = onerror;
QUnit.start(); done();
}; };
jQuery.ajax( { jQuery.ajax( {
url: baseURL + "badjson.js", url: baseURL + "badjson.js",
@ -2148,29 +2159,33 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
//----------- jQuery.ajaxSetup() //----------- jQuery.ajaxSetup()
QUnit.asyncTest( "jQuery.ajaxSetup()", 1, function( assert ) { QUnit.test( "jQuery.ajaxSetup()", function( assert ) {
assert.expect( 1 );
var done = assert.async();
jQuery.ajaxSetup( { jQuery.ajaxSetup( {
url: url( "mock.php?action=name&name=foo" ), url: url( "mock.php?action=name&name=foo" ),
success: function( msg ) { success: function( msg ) {
assert.strictEqual( msg, "bar", "Check for GET" ); assert.strictEqual( msg, "bar", "Check for GET" );
QUnit.start(); done();
} }
} ); } );
jQuery.ajax(); jQuery.ajax();
} ); } );
QUnit.asyncTest( "jQuery.ajaxSetup({ timeout: Number }) - with global timeout", 2, function( assert ) { QUnit.test( "jQuery.ajaxSetup({ timeout: Number }) - with global timeout", function( assert ) {
assert.expect( 2 );
var done = assert.async();
var passed = 0, var passed = 0,
pass = function() { pass = function() {
assert.ok( passed++ < 2, "Error callback executed" ); assert.ok( passed++ < 2, "Error callback executed" );
if ( passed === 2 ) { if ( passed === 2 ) {
jQuery( document ).off( "ajaxError.setupTest" ); jQuery( document ).off( "ajaxError.setupTest" );
QUnit.start(); done();
} }
}, },
fail = function( a, b ) { fail = function( a, b ) {
assert.ok( false, "Check for timeout failed " + a + " " + b ); assert.ok( false, "Check for timeout failed " + a + " " + b );
QUnit.start(); done();
}; };
jQuery( document ).on( "ajaxError.setupTest", pass ); jQuery( document ).on( "ajaxError.setupTest", pass );
@ -2187,7 +2202,9 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} ); } );
} ); } );
QUnit.asyncTest( "jQuery.ajaxSetup({ timeout: Number }) with localtimeout", 1, function( assert ) { QUnit.test( "jQuery.ajaxSetup({ timeout: Number }) with localtimeout", function( assert ) {
assert.expect( 1 );
var done = assert.async();
jQuery.ajaxSetup( { jQuery.ajaxSetup( {
timeout: 50 timeout: 50
} ); } );
@ -2197,11 +2214,11 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
url: url( "mock.php?action=wait&wait=1" ), url: url( "mock.php?action=wait&wait=1" ),
error: function() { error: function() {
assert.ok( false, "Check for local timeout failed" ); assert.ok( false, "Check for local timeout failed" );
QUnit.start(); done();
}, },
success: function() { success: function() {
assert.ok( true, "Check for local timeout" ); assert.ok( true, "Check for local timeout" );
QUnit.start(); done();
} }
} ); } );
} ); } );
@ -2225,8 +2242,9 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} ); } );
QUnit.test( QUnit.test(
"jQuery#load() - always use GET method even if it overrided through ajaxSetup (#11264)", 1, "jQuery#load() - always use GET method even if it overrided through ajaxSetup (#11264)",
function( assert ) { function( assert ) {
assert.expect( 1 );
var done = assert.async(); var done = assert.async();
jQuery.ajaxSetup( { jQuery.ajaxSetup( {
@ -2241,8 +2259,9 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
); );
QUnit.test( QUnit.test(
"jQuery#load() - should resolve with correct context", 2, "jQuery#load() - should resolve with correct context",
function( assert ) { function( assert ) {
assert.expect( 2 );
var done = assert.async(); var done = assert.async();
var ps = jQuery( "<p></p><p></p>" ); var ps = jQuery( "<p></p><p></p>" );
var i = 0; var i = 0;
@ -2260,15 +2279,18 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
); );
QUnit.test( QUnit.test(
"#11402 - jQuery.domManip() - script in comments are properly evaluated", 2, "#11402 - jQuery.domManip() - script in comments are properly evaluated",
function( assert ) { function( assert ) {
assert.expect( 2 );
jQuery( "#qunit-fixture" ).load( baseURL + "cleanScript.html", assert.async() ); jQuery( "#qunit-fixture" ).load( baseURL + "cleanScript.html", assert.async() );
} }
); );
//----------- jQuery.get() //----------- jQuery.get()
QUnit.asyncTest( "jQuery.get( String, Hash, Function ) - parse xml and use text() on nodes", 2, function( assert ) { QUnit.test( "jQuery.get( String, Hash, Function ) - parse xml and use text() on nodes", function( assert ) {
assert.expect( 2 );
var done = assert.async();
jQuery.get( url( "dashboard.xml" ), function( xml ) { jQuery.get( url( "dashboard.xml" ), function( xml ) {
var content = []; var content = [];
jQuery( "tab", xml ).each( function() { jQuery( "tab", xml ).each( function() {
@ -2276,23 +2298,27 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} ); } );
assert.strictEqual( content[ 0 ], "blabla", "Check first tab" ); assert.strictEqual( content[ 0 ], "blabla", "Check first tab" );
assert.strictEqual( content[ 1 ], "blublu", "Check second tab" ); assert.strictEqual( content[ 1 ], "blublu", "Check second tab" );
QUnit.start(); done();
} ); } );
} ); } );
QUnit.asyncTest( "#8277 - jQuery.get( String, Function ) - data in ajaxSettings", 1, function( assert ) { QUnit.test( "#8277 - jQuery.get( String, Function ) - data in ajaxSettings", function( assert ) {
assert.expect( 1 );
var done = assert.async();
jQuery.ajaxSetup( { jQuery.ajaxSetup( {
data: "helloworld" data: "helloworld"
} ); } );
jQuery.get( url( "mock.php?action=echoQuery" ), function( data ) { jQuery.get( url( "mock.php?action=echoQuery" ), function( data ) {
assert.ok( /helloworld$/.test( data ), "Data from ajaxSettings was used" ); assert.ok( /helloworld$/.test( data ), "Data from ajaxSettings was used" );
QUnit.start(); done();
} ); } );
} ); } );
//----------- jQuery.getJSON() //----------- jQuery.getJSON()
QUnit.asyncTest( "jQuery.getJSON( String, Hash, Function ) - JSON array", 5, function( assert ) { QUnit.test( "jQuery.getJSON( String, Hash, Function ) - JSON array", function( assert ) {
assert.expect( 5 );
var done = assert.async();
jQuery.getJSON( jQuery.getJSON(
url( "mock.php?action=json" ), url( "mock.php?action=json" ),
{ {
@ -2304,22 +2330,26 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
assert.strictEqual( json[ 0 ][ "age" ], 21, "Check JSON: first, age" ); assert.strictEqual( json[ 0 ][ "age" ], 21, "Check JSON: first, age" );
assert.strictEqual( json[ 1 ][ "name" ], "Peter", "Check JSON: second, name" ); assert.strictEqual( json[ 1 ][ "name" ], "Peter", "Check JSON: second, name" );
assert.strictEqual( json[ 1 ][ "age" ], 25, "Check JSON: second, age" ); assert.strictEqual( json[ 1 ][ "age" ], 25, "Check JSON: second, age" );
QUnit.start(); done();
} }
); );
} ); } );
QUnit.asyncTest( "jQuery.getJSON( String, Function ) - JSON object", 2, function( assert ) { QUnit.test( "jQuery.getJSON( String, Function ) - JSON object", function( assert ) {
assert.expect( 2 );
var done = assert.async();
jQuery.getJSON( url( "mock.php?action=json" ), function( json ) { jQuery.getJSON( url( "mock.php?action=json" ), function( json ) {
if ( json && json[ "data" ] ) { if ( json && json[ "data" ] ) {
assert.strictEqual( json[ "data" ][ "lang" ], "en", "Check JSON: lang" ); assert.strictEqual( json[ "data" ][ "lang" ], "en", "Check JSON: lang" );
assert.strictEqual( json[ "data" ].length, 25, "Check JSON: length" ); assert.strictEqual( json[ "data" ].length, 25, "Check JSON: length" );
QUnit.start(); done();
} }
} ); } );
} ); } );
QUnit.asyncTest( "jQuery.getJSON( String, Function ) - JSON object with absolute url to local content", 2, function( assert ) { QUnit.test( "jQuery.getJSON( String, Function ) - JSON object with absolute url to local content", function( assert ) {
assert.expect( 2 );
var done = assert.async();
var absoluteUrl = url( "mock.php?action=json" ); var absoluteUrl = url( "mock.php?action=json" );
// Make a relative URL absolute relative to the document location // Make a relative URL absolute relative to the document location
@ -2338,14 +2368,15 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
jQuery.getJSON( absoluteUrl, function( json ) { jQuery.getJSON( absoluteUrl, function( json ) {
assert.strictEqual( json.data.lang, "en", "Check JSON: lang" ); assert.strictEqual( json.data.lang, "en", "Check JSON: lang" );
assert.strictEqual( json.data.length, 25, "Check JSON: length" ); assert.strictEqual( json.data.length, 25, "Check JSON: length" );
QUnit.start(); done();
} ); } );
} ); } );
//----------- jQuery.getScript() //----------- jQuery.getScript()
QUnit.test( "jQuery.getScript( String, Function ) - with callback", 2, QUnit.test( "jQuery.getScript( String, Function ) - with callback",
function( assert ) { function( assert ) {
assert.expect( 2 );
var done = assert.async(); var done = assert.async();
Globals.register( "testBar" ); Globals.register( "testBar" );
@ -2356,12 +2387,14 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} }
); );
QUnit.test( "jQuery.getScript( String, Function ) - no callback", 1, function( assert ) { QUnit.test( "jQuery.getScript( String, Function ) - no callback", function( assert ) {
assert.expect( 1 );
Globals.register( "testBar" ); Globals.register( "testBar" );
jQuery.getScript( url( "mock.php?action=testbar" ) ).done( assert.async() ); jQuery.getScript( url( "mock.php?action=testbar" ) ).done( assert.async() );
} ); } );
QUnit.test( "#8082 - jQuery.getScript( String, Function ) - source as responseText", 2, function( assert ) { QUnit.test( "#8082 - jQuery.getScript( String, Function ) - source as responseText", function( assert ) {
assert.expect( 2 );
var done = assert.async(); var done = assert.async();
Globals.register( "testBar" ); Globals.register( "testBar" );
@ -2371,7 +2404,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} ); } );
} ); } );
QUnit.test( "jQuery.getScript( Object ) - with callback", 2, function( assert ) { QUnit.test( "jQuery.getScript( Object ) - with callback", function( assert ) {
assert.expect( 2 );
var done = assert.async(); var done = assert.async();
Globals.register( "testBar" ); Globals.register( "testBar" );
@ -2384,7 +2418,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} ); } );
} ); } );
QUnit.test( "jQuery.getScript( Object ) - no callback", 1, function( assert ) { QUnit.test( "jQuery.getScript( Object ) - no callback", function( assert ) {
assert.expect( 1 );
Globals.register( "testBar" ); Globals.register( "testBar" );
jQuery.getScript( { url: url( "mock.php?action=testbar" ) } ).done( assert.async() ); jQuery.getScript( { url: url( "mock.php?action=testbar" ) } ).done( assert.async() );
} ); } );
@ -2392,7 +2427,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
// //----------- jQuery.fn.load() // //----------- jQuery.fn.load()
// check if load can be called with only url // check if load can be called with only url
QUnit.test( "jQuery.fn.load( String )", 2, function( assert ) { QUnit.test( "jQuery.fn.load( String )", function( assert ) {
assert.expect( 2 );
jQuery.ajaxSetup( { jQuery.ajaxSetup( {
beforeSend: function() { beforeSend: function() {
assert.strictEqual( this.type, "GET", "no data means GET request" ); assert.strictEqual( this.type, "GET", "no data means GET request" );
@ -2413,7 +2449,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} ); } );
// check if load can be called with url and null data // check if load can be called with url and null data
QUnit.test( "jQuery.fn.load( String, null )", 2, function( assert ) { QUnit.test( "jQuery.fn.load( String, null )", function( assert ) {
assert.expect( 2 );
jQuery.ajaxSetup( { jQuery.ajaxSetup( {
beforeSend: function() { beforeSend: function() {
assert.strictEqual( this.type, "GET", "no data means GET request" ); assert.strictEqual( this.type, "GET", "no data means GET request" );
@ -2423,7 +2460,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} ); } );
// check if load can be called with url and undefined data // check if load can be called with url and undefined data
QUnit.test( "jQuery.fn.load( String, undefined )", 2, function( assert ) { QUnit.test( "jQuery.fn.load( String, undefined )", function( assert ) {
assert.expect( 2 );
jQuery.ajaxSetup( { jQuery.ajaxSetup( {
beforeSend: function() { beforeSend: function() {
assert.strictEqual( this.type, "GET", "no data means GET request" ); assert.strictEqual( this.type, "GET", "no data means GET request" );
@ -2433,18 +2471,22 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} ); } );
// check if load can be called with only url // check if load can be called with only url
QUnit.asyncTest( "jQuery.fn.load( URL_SELECTOR )", 1, function( assert ) { QUnit.test( "jQuery.fn.load( URL_SELECTOR )", function( assert ) {
assert.expect( 1 );
var done = assert.async();
jQuery( "#first" ).load( baseURL + "test3.html div.user", function() { jQuery( "#first" ).load( baseURL + "test3.html div.user", function() {
assert.strictEqual( jQuery( this ).children( "div" ).length, 2, "Verify that specific elements were injected" ); assert.strictEqual( jQuery( this ).children( "div" ).length, 2, "Verify that specific elements were injected" );
QUnit.start(); done();
} ); } );
} ); } );
// Selector should be trimmed to avoid leading spaces (#14773) // Selector should be trimmed to avoid leading spaces (#14773)
QUnit.asyncTest( "jQuery.fn.load( URL_SELECTOR with spaces )", 1, function( assert ) { QUnit.test( "jQuery.fn.load( URL_SELECTOR with spaces )", function( assert ) {
assert.expect( 1 );
var done = assert.async();
jQuery( "#first" ).load( baseURL + "test3.html #superuser ", function() { jQuery( "#first" ).load( baseURL + "test3.html #superuser ", function() {
assert.strictEqual( jQuery( this ).children( "div" ).length, 1, "Verify that specific elements were injected" ); assert.strictEqual( jQuery( this ).children( "div" ).length, 1, "Verify that specific elements were injected" );
QUnit.start(); done();
} ); } );
} ); } );
@ -2459,18 +2501,22 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} ); } );
} ); } );
QUnit.asyncTest( "jQuery.fn.load( String, Function ) - simple: inject text into DOM", 2, function( assert ) { QUnit.test( "jQuery.fn.load( String, Function ) - simple: inject text into DOM", function( assert ) {
assert.expect( 2 );
var done = assert.async();
jQuery( "#first" ).load( url( "name.html" ), function() { jQuery( "#first" ).load( url( "name.html" ), function() {
assert.ok( /^ERROR/.test( jQuery( "#first" ).text() ), "Check if content was injected into the DOM" ); assert.ok( /^ERROR/.test( jQuery( "#first" ).text() ), "Check if content was injected into the DOM" );
QUnit.start(); done();
} ); } );
} ); } );
QUnit.asyncTest( "jQuery.fn.load( String, Function ) - check scripts", 7, function( assert ) { QUnit.test( "jQuery.fn.load( String, Function ) - check scripts", function( assert ) {
assert.expect( 7 );
var done = assert.async();
var verifyEvaluation = function() { var verifyEvaluation = function() {
assert.strictEqual( window[ "testBar" ], "bar", "Check if script src was evaluated after load" ); assert.strictEqual( window[ "testBar" ], "bar", "Check if script src was evaluated after load" );
assert.strictEqual( jQuery( "#ap" ).html(), "bar", "Check if script evaluation has modified DOM" ); assert.strictEqual( jQuery( "#ap" ).html(), "bar", "Check if script evaluation has modified DOM" );
QUnit.start(); done();
}; };
Globals.register( "testFoo" ); Globals.register( "testFoo" );
@ -2484,17 +2530,21 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} ); } );
} ); } );
QUnit.asyncTest( "jQuery.fn.load( String, Function ) - check file with only a script tag", 3, function( assert ) { QUnit.test( "jQuery.fn.load( String, Function ) - check file with only a script tag", function( assert ) {
assert.expect( 3 );
var done = assert.async();
Globals.register( "testFoo" ); Globals.register( "testFoo" );
jQuery( "#first" ).load( url( "test2.html" ), function() { jQuery( "#first" ).load( url( "test2.html" ), function() {
assert.strictEqual( jQuery( "#foo" ).html(), "foo", "Check if script evaluation has modified DOM" ); assert.strictEqual( jQuery( "#foo" ).html(), "foo", "Check if script evaluation has modified DOM" );
assert.strictEqual( window[ "testFoo" ], "foo", "Check if script was evaluated after load" ); assert.strictEqual( window[ "testFoo" ], "foo", "Check if script was evaluated after load" );
QUnit.start(); done();
} ); } );
} ); } );
QUnit.asyncTest( "jQuery.fn.load( String, Function ) - dataFilter in ajaxSettings", 2, function( assert ) { QUnit.test( "jQuery.fn.load( String, Function ) - dataFilter in ajaxSettings", function( assert ) {
assert.expect( 2 );
var done = assert.async();
jQuery.ajaxSetup( { jQuery.ajaxSetup( {
dataFilter: function() { dataFilter: function() {
return "Hello World"; return "Hello World";
@ -2503,22 +2553,25 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
jQuery( "<div/>" ).load( url( "name.html" ), function( responseText ) { jQuery( "<div/>" ).load( url( "name.html" ), function( responseText ) {
assert.strictEqual( jQuery( this ).html(), "Hello World", "Test div was filled with filtered data" ); assert.strictEqual( jQuery( this ).html(), "Hello World", "Test div was filled with filtered data" );
assert.strictEqual( responseText, "Hello World", "Test callback receives filtered data" ); assert.strictEqual( responseText, "Hello World", "Test callback receives filtered data" );
QUnit.start(); done();
} ); } );
} ); } );
QUnit.asyncTest( "jQuery.fn.load( String, Object, Function )", 2, function( assert ) { QUnit.test( "jQuery.fn.load( String, Object, Function )", function( assert ) {
assert.expect( 2 );
var done = assert.async();
jQuery( "<div />" ).load( url( "mock.php?action=echoHtml" ), { jQuery( "<div />" ).load( url( "mock.php?action=echoHtml" ), {
"bar": "ok" "bar": "ok"
}, function() { }, function() {
var $node = jQuery( this ); var $node = jQuery( this );
assert.strictEqual( $node.find( "#method" ).text(), "POST", "Check method" ); assert.strictEqual( $node.find( "#method" ).text(), "POST", "Check method" );
assert.strictEqual( $node.find( "#data" ).text(), "bar=ok", "Check if data is passed correctly" ); assert.strictEqual( $node.find( "#data" ).text(), "bar=ok", "Check if data is passed correctly" );
QUnit.start(); done();
} ); } );
} ); } );
QUnit.test( "jQuery.fn.load( String, String, Function )", 2, function( assert ) { QUnit.test( "jQuery.fn.load( String, String, Function )", function( assert ) {
assert.expect( 2 );
var done = assert.async(); var done = assert.async();
jQuery( "<div />" ).load( url( "mock.php?action=echoHtml" ), "foo=3&bar=ok", function() { jQuery( "<div />" ).load( url( "mock.php?action=echoHtml" ), "foo=3&bar=ok", function() {
@ -2529,9 +2582,10 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} ); } );
} ); } );
QUnit.test( "jQuery.fn.load() - callbacks get the correct parameters", 8, function( assert ) { QUnit.test( "jQuery.fn.load() - callbacks get the correct parameters", function( assert ) {
var completeArgs = {}; assert.expect( 8 );
var done = assert.async(); var completeArgs = {},
done = assert.async();
jQuery.ajaxSetup( { jQuery.ajaxSetup( {
success: function( _, status, jqXHR ) { success: function( _, status, jqXHR ) {
@ -2569,7 +2623,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
).always( done ); ).always( done );
} ); } );
QUnit.test( "#2046 - jQuery.fn.load( String, Function ) with ajaxSetup on dataType json", 1, function( assert ) { QUnit.test( "#2046 - jQuery.fn.load( String, Function ) with ajaxSetup on dataType json", function( assert ) {
assert.expect( 1 );
var done = assert.async(); var done = assert.async();
jQuery.ajaxSetup( { jQuery.ajaxSetup( {
@ -2583,7 +2638,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
jQuery( "#first" ).load( baseURL + "test3.html" ); jQuery( "#first" ).load( baseURL + "test3.html" );
} ); } );
QUnit.test( "#10524 - jQuery.fn.load() - data specified in ajaxSettings is merged in", 1, function( assert ) { QUnit.test( "#10524 - jQuery.fn.load() - data specified in ajaxSettings is merged in", function( assert ) {
assert.expect( 1 );
var done = assert.async(); var done = assert.async();
var data = { var data = {
@ -2603,7 +2659,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
// //----------- jQuery.post() // //----------- jQuery.post()
QUnit.test( "jQuery.post() - data", 3, function( assert ) { QUnit.test( "jQuery.post() - data", function( assert ) {
assert.expect( 3 );
var done = assert.async(); var done = assert.async();
jQuery.when( jQuery.when(
@ -2635,7 +2692,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
).always( done ); ).always( done );
} ); } );
QUnit.test( "jQuery.post( String, Hash, Function ) - simple with xml", 4, function( assert ) { QUnit.test( "jQuery.post( String, Hash, Function ) - simple with xml", function( assert ) {
assert.expect( 4 );
var done = assert.async(); var done = assert.async();
jQuery.when( jQuery.when(
@ -2662,7 +2720,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} ); } );
} ); } );
QUnit.test( "jQuery[get|post]( options ) - simple with xml", 2, function( assert ) { QUnit.test( "jQuery[get|post]( options ) - simple with xml", function( assert ) {
assert.expect( 2 );
var done = assert.async(); var done = assert.async();
jQuery.when.apply( jQuery, jQuery.when.apply( jQuery,

View File

@ -12,7 +12,7 @@ var oldRaf = window.requestAnimationFrame,
// This module tests jQuery.Animation and the corresponding 1.8+ effects APIs // This module tests jQuery.Animation and the corresponding 1.8+ effects APIs
QUnit.module( "animation", { QUnit.module( "animation", {
setup: function() { beforeEach: function() {
window.requestAnimationFrame = null; window.requestAnimationFrame = null;
this.sandbox = sinon.sandbox.create(); this.sandbox = sinon.sandbox.create();
this.clock = this.sandbox.useFakeTimers( startTime ); this.clock = this.sandbox.useFakeTimers( startTime );
@ -22,7 +22,7 @@ QUnit.module( "animation", {
jQuery.Animation.prefilters = [ defaultPrefilter ]; jQuery.Animation.prefilters = [ defaultPrefilter ];
jQuery.Animation.tweeners = { "*": [ defaultTweener ] }; jQuery.Animation.tweeners = { "*": [ defaultTweener ] };
}, },
teardown: function() { afterEach: function() {
this.sandbox.restore(); this.sandbox.restore();
jQuery.fx.stop(); jQuery.fx.stop();
jQuery.fx.interval = this._oldInterval; jQuery.fx.interval = this._oldInterval;

View File

@ -1,5 +1,5 @@
QUnit.module( "attributes", { QUnit.module( "attributes", {
teardown: moduleTeardown afterEach: moduleTeardown
} ); } );
function bareObj( value ) { function bareObj( value ) {

View File

@ -1,4 +1,4 @@
QUnit.module( "basic", { teardown: moduleTeardown } ); QUnit.module( "basic", { afterEach: moduleTeardown } );
if ( jQuery.ajax ) { if ( jQuery.ajax ) {
QUnit.test( "ajax", function( assert ) { QUnit.test( "ajax", function( assert ) {

View File

@ -1,5 +1,5 @@
QUnit.module( "callbacks", { QUnit.module( "callbacks", {
teardown: moduleTeardown afterEach: moduleTeardown
} ); } );
( function() { ( function() {

View File

@ -1,8 +1,8 @@
QUnit.module( "core", { QUnit.module( "core", {
setup: function() { beforeEach: function() {
this.sandbox = sinon.sandbox.create(); this.sandbox = sinon.sandbox.create();
}, },
teardown: function() { afterEach: function() {
this.sandbox.restore(); this.sandbox.restore();
return moduleTeardown.apply( this, arguments ); return moduleTeardown.apply( this, arguments );
} }
@ -238,7 +238,8 @@ QUnit.test( "trim", function( assert ) {
assert.equal( jQuery.trim( "\uFEFF \xA0! | \uFEFF" ), "! |", "leading/trailing should be trimmed" ); assert.equal( jQuery.trim( "\uFEFF \xA0! | \uFEFF" ), "! |", "leading/trailing should be trimmed" );
} ); } );
QUnit.asyncTest( "isPlainObject", function( assert ) { QUnit.test( "isPlainObject", function( assert ) {
var done = assert.async();
assert.expect( 23 ); assert.expect( 23 );
@ -314,7 +315,7 @@ QUnit.asyncTest( "isPlainObject", function( assert ) {
window.iframeDone = undefined; window.iframeDone = undefined;
iframe.parentNode.removeChild( iframe ); iframe.parentNode.removeChild( iframe );
assert.ok( jQuery.isPlainObject( new otherObject() ), "new otherObject" + ( detail ? " - " + detail : "" ) ); assert.ok( jQuery.isPlainObject( new otherObject() ), "new otherObject" + ( detail ? " - " + detail : "" ) );
QUnit.start(); done();
}; };
try { try {
@ -380,14 +381,14 @@ QUnit.test( "isXMLDoc - HTML", function( assert ) {
} ); } );
QUnit.test( "XSS via location.hash", function( assert ) { QUnit.test( "XSS via location.hash", function( assert ) {
var done = assert.async();
assert.expect( 1 ); assert.expect( 1 );
QUnit.stop();
jQuery[ "_check9521" ] = function( x ) { jQuery[ "_check9521" ] = function( x ) {
assert.ok( x, "script called from #id-like selector with inline handler" ); assert.ok( x, "script called from #id-like selector with inline handler" );
jQuery( "#check9521" ).remove(); jQuery( "#check9521" ).remove();
delete jQuery[ "_check9521" ]; delete jQuery[ "_check9521" ];
QUnit.start(); done();
}; };
try { try {
@ -1312,7 +1313,8 @@ QUnit.test( "jQuery.parseHTML(<a href>) - gh-2965", function( assert ) {
} ); } );
if ( jQuery.support.createHTMLDocument ) { if ( jQuery.support.createHTMLDocument ) {
QUnit.asyncTest( "jQuery.parseHTML", function( assert ) { QUnit.test( "jQuery.parseHTML", function( assert ) {
var done = assert.async();
assert.expect( 1 ); assert.expect( 1 );
Globals.register( "parseHTMLError" ); Globals.register( "parseHTMLError" );
@ -1321,8 +1323,8 @@ if ( jQuery.support.createHTMLDocument ) {
jQuery.parseHTML( "<img src=x onerror='parseHTMLError = true'>" ); jQuery.parseHTML( "<img src=x onerror='parseHTMLError = true'>" );
window.setTimeout( function() { window.setTimeout( function() {
QUnit.start();
assert.equal( window.parseHTMLError, false, "onerror eventhandler has not been called." ); assert.equal( window.parseHTMLError, false, "onerror eventhandler has not been called." );
done();
}, 2000 ); }, 2000 );
} ); } );
} }

View File

@ -1,6 +1,6 @@
if ( jQuery.css ) { if ( jQuery.css ) {
QUnit.module( "css", { teardown: moduleTeardown } ); QUnit.module( "css", { afterEach: moduleTeardown } );
QUnit.test( "css(String|Hash)", function( assert ) { QUnit.test( "css(String|Hash)", function( assert ) {
assert.expect( 42 ); assert.expect( 42 );
@ -1503,8 +1503,8 @@ QUnit.test( "Reset the style if set to an empty string", function( assert ) {
QUnit.test( QUnit.test(
"Clearing a Cloned Element's Style Shouldn't Clear the Original Element's Style (#8908)", "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's Style (#8908)",
24,
function( assert ) { function( assert ) {
assert.expect( 24 );
var done = assert.async(); var done = assert.async();
var styles = [ { var styles = [ {
name: "backgroundAttachment", name: "backgroundAttachment",

View File

@ -1,4 +1,4 @@
QUnit.module( "data", { teardown: moduleTeardown } ); QUnit.module( "data", { afterEach: moduleTeardown } );
QUnit.test( "expando", function( assert ) { QUnit.test( "expando", function( assert ) {
assert.expect( 1 ); assert.expect( 1 );
@ -832,12 +832,12 @@ QUnit.test( ".removeData supports removal of hyphenated properties via array (#1
// Test originally by Moschel // Test originally by Moschel
QUnit.test( ".removeData should not throw exceptions. (#10080)", function( assert ) { QUnit.test( ".removeData should not throw exceptions. (#10080)", function( assert ) {
var done = assert.async();
assert.expect( 1 ); assert.expect( 1 );
QUnit.stop();
var frame = jQuery( "#loadediframe" ); var frame = jQuery( "#loadediframe" );
jQuery( frame[ 0 ].contentWindow ).on( "unload", function() { jQuery( frame[ 0 ].contentWindow ).on( "unload", function() {
assert.ok( true, "called unload" ); assert.ok( true, "called unload" );
QUnit.start(); done();
} ); } );
// change the url to trigger unload // change the url to trigger unload

View File

@ -1,5 +1,5 @@
QUnit.module( "deferred", { QUnit.module( "deferred", {
teardown: moduleTeardown afterEach: moduleTeardown
} ); } );
jQuery.each( [ "", " - new operator" ], function( _, withNew ) { jQuery.each( [ "", " - new operator" ], function( _, withNew ) {

View File

@ -1,4 +1,4 @@
QUnit.module( "deprecated", { teardown: moduleTeardown } ); QUnit.module( "deprecated", { afterEach: moduleTeardown } );
QUnit.test( "bind/unbind", function( assert ) { QUnit.test( "bind/unbind", function( assert ) {

View File

@ -4,7 +4,7 @@ if ( !jQuery.fn.width ) {
return; return;
} }
QUnit.module( "dimensions", { teardown: moduleTeardown } ); QUnit.module( "dimensions", { afterEach: moduleTeardown } );
function pass( val ) { function pass( val ) {
return val; return val;

View File

@ -12,7 +12,7 @@ var oldRaf = window.requestAnimationFrame,
}; };
QUnit.module( "effects", { QUnit.module( "effects", {
setup: function() { beforeEach: function() {
window.requestAnimationFrame = null; window.requestAnimationFrame = null;
this.sandbox = sinon.sandbox.create(); this.sandbox = sinon.sandbox.create();
this.clock = this.sandbox.useFakeTimers( 505877050 ); this.clock = this.sandbox.useFakeTimers( 505877050 );
@ -20,7 +20,7 @@ QUnit.module( "effects", {
jQuery.fx.step = {}; jQuery.fx.step = {};
jQuery.fx.interval = 10; jQuery.fx.interval = 10;
}, },
teardown: function() { afterEach: function() {
this.sandbox.restore(); this.sandbox.restore();
jQuery.fx.stop(); jQuery.fx.stop();
jQuery.fx.interval = this._oldInterval; jQuery.fx.interval = this._oldInterval;
@ -453,8 +453,8 @@ QUnit.test( "animate resets overflow-x and overflow-y when finished", function(
/* // This test ends up being flaky depending upon the CPU load /* // This test ends up being flaky depending upon the CPU load
QUnit.test("animate option (queue === false)", function( assert ) { QUnit.test("animate option (queue === false)", function( assert ) {
var done = assert.async();
assert.expect(1); assert.expect(1);
QUnit.stop();
var order = []; var order = [];
@ -463,7 +463,7 @@ QUnit.test("animate option (queue === false)", function( assert ) {
// should finish after unqueued animation so second // should finish after unqueued animation so second
order.push(2); order.push(2);
assert.deepEqual( order, [ 1, 2 ], "Animations finished in the correct order" ); assert.deepEqual( order, [ 1, 2 ], "Animations finished in the correct order" );
QUnit.start(); done();
}); });
$foo.animate({fontSize:"2em"}, {queue:false, duration:10, complete:function () { $foo.animate({fontSize:"2em"}, {queue:false, duration:10, complete:function () {
// short duration and out of queue so should finish first // short duration and out of queue so should finish first

View File

@ -1,8 +1,8 @@
QUnit.module( "event", { QUnit.module( "event", {
setup: function() { beforeEach: function() {
document.body.focus(); document.body.focus();
}, },
teardown: moduleTeardown afterEach: moduleTeardown
} ); } );
QUnit.test( "null or undefined handler", function( assert ) { QUnit.test( "null or undefined handler", function( assert ) {
@ -1418,7 +1418,8 @@ QUnit.test( "Submit event can be stopped (#11049)", function( assert ) {
// iOS has the window.onbeforeunload field but doesn't support the beforeunload // iOS has the window.onbeforeunload field but doesn't support the beforeunload
// handler making it impossible to feature-detect the support. // handler making it impossible to feature-detect the support.
QUnit[ /(ipad|iphone|ipod)/i.test( navigator.userAgent ) ? "skip" : "test" ]( QUnit[ /(ipad|iphone|ipod)/i.test( navigator.userAgent ) ? "skip" : "test" ](
"on(beforeunload)", 1, function( assert ) { "on(beforeunload)", function( assert ) {
assert.expect( 1 );
var iframe = jQuery( jQuery.parseHTML( "<iframe src='" + baseURL + "event/onbeforeunload.html'><iframe>" ) ); var iframe = jQuery( jQuery.parseHTML( "<iframe src='" + baseURL + "event/onbeforeunload.html'><iframe>" ) );
var done = assert.async(); var done = assert.async();

View File

@ -1,4 +1,4 @@
QUnit.module( "exports", { teardown: moduleTeardown } ); QUnit.module( "exports", { afterEach: moduleTeardown } );
QUnit.test( "amdModule", function( assert ) { QUnit.test( "amdModule", function( assert ) {
assert.expect( 1 ); assert.expect( 1 );

View File

@ -1,5 +1,5 @@
QUnit.module( "manipulation", { QUnit.module( "manipulation", {
teardown: moduleTeardown afterEach: moduleTeardown
} ); } );
// Ensure that an extended Array prototype doesn't break jQuery // Ensure that an extended Array prototype doesn't break jQuery
@ -1300,7 +1300,7 @@ function testReplaceWith( val, assert ) {
$div = jQuery( "<div class='replacewith'></div>" ).appendTo( "#qunit-fixture" ); $div = jQuery( "<div class='replacewith'></div>" ).appendTo( "#qunit-fixture" );
$div.replaceWith( val( "<div class='replacewith'></div><script>" + $div.replaceWith( val( "<div class='replacewith'></div><script>" +
"equal( jQuery('.replacewith').length, 1, 'Check number of elements in page.' );" + "QUnit.assert.equal( jQuery('.replacewith').length, 1, 'Check number of elements in page.' );" +
"</script>" ) ); "</script>" ) );
jQuery( "#qunit-fixture" ).append( "<div id='replaceWith'></div>" ); jQuery( "#qunit-fixture" ).append( "<div id='replaceWith'></div>" );
@ -1754,15 +1754,15 @@ function testHtml( valueObj, assert ) {
tmp = fixture.html( tmp = fixture.html(
valueObj( [ valueObj( [
"<script type='something/else'>ok( false, 'evaluated: non-script' );</script>", "<script type='something/else'>QUnit.assert.ok( false, 'evaluated: non-script' );</script>",
"<script type='text/javascript'>ok( true, 'evaluated: text/javascript' );</script>", "<script type='text/javascript'>QUnit.assert.ok( true, 'evaluated: text/javascript' );</script>",
"<script type='text/ecmascript'>ok( true, 'evaluated: text/ecmascript' );</script>", "<script type='text/ecmascript'>QUnit.assert.ok( true, 'evaluated: text/ecmascript' );</script>",
"<script>ok( true, 'evaluated: no type' );</script>", "<script>QUnit.assert.ok( true, 'evaluated: no type' );</script>",
"<div>", "<div>",
"<script type='something/else'>ok( false, 'evaluated: inner non-script' );</script>", "<script type='something/else'>QUnit.assert.ok( false, 'evaluated: inner non-script' );</script>",
"<script type='text/javascript'>ok( true, 'evaluated: inner text/javascript' );</script>", "<script type='text/javascript'>QUnit.assert.ok( true, 'evaluated: inner text/javascript' );</script>",
"<script type='text/ecmascript'>ok( true, 'evaluated: inner text/ecmascript' );</script>", "<script type='text/ecmascript'>QUnit.assert.ok( true, 'evaluated: inner text/ecmascript' );</script>",
"<script>ok( true, 'evaluated: inner no type' );</script>", "<script>QUnit.assert.ok( true, 'evaluated: inner no type' );</script>",
"</div>" "</div>"
].join( "" ) ) ].join( "" ) )
).find( "script" ); ).find( "script" );
@ -1770,19 +1770,19 @@ function testHtml( valueObj, assert ) {
assert.equal( tmp[ 0 ].type, "something/else", "Non-evaluated type." ); assert.equal( tmp[ 0 ].type, "something/else", "Non-evaluated type." );
assert.equal( tmp[ 1 ].type, "text/javascript", "Evaluated type." ); assert.equal( tmp[ 1 ].type, "text/javascript", "Evaluated type." );
fixture.html( valueObj( "<script type='text/javascript'>ok( true, 'Injection of identical script' );</script>" ) ); fixture.html( valueObj( "<script type='text/javascript'>QUnit.assert.ok( true, 'Injection of identical script' );</script>" ) );
fixture.html( valueObj( "<script type='text/javascript'>ok( true, 'Injection of identical script' );</script>" ) ); fixture.html( valueObj( "<script type='text/javascript'>QUnit.assert.ok( true, 'Injection of identical script' );</script>" ) );
fixture.html( valueObj( "<script type='text/javascript'>ok( true, 'Injection of identical script' );</script>" ) ); fixture.html( valueObj( "<script type='text/javascript'>QUnit.assert.ok( true, 'Injection of identical script' );</script>" ) );
fixture.html( valueObj( "foo <form><script type='text/javascript'>ok( true, 'Injection of identical script (#975)' );</script></form>" ) ); fixture.html( valueObj( "foo <form><script type='text/javascript'>QUnit.assert.ok( true, 'Injection of identical script (#975)' );</script></form>" ) );
jQuery.scriptorder = 0; jQuery.scriptorder = 0;
fixture.html( valueObj( [ fixture.html( valueObj( [
"<script>", "<script>",
"equal( jQuery('#scriptorder').length, 1,'Execute after html' );", "QUnit.assert.equal( jQuery('#scriptorder').length, 1,'Execute after html' );",
"equal( jQuery.scriptorder++, 0, 'Script is executed in order' );", "QUnit.assert.equal( jQuery.scriptorder++, 0, 'Script is executed in order' );",
"</script>", "</script>",
"<span id='scriptorder'><script>equal( jQuery.scriptorder++, 1, 'Script (nested) is executed in order');</script></span>", "<span id='scriptorder'><script>QUnit.assert.equal( jQuery.scriptorder++, 1, 'Script (nested) is executed in order');</script></span>",
"<script>equal( jQuery.scriptorder++, 2, 'Script (unnested) is executed in order' );</script>" "<script>QUnit.assert.equal( jQuery.scriptorder++, 2, 'Script (unnested) is executed in order' );</script>"
].join( "" ) ) ); ].join( "" ) ) );
fixture.html( valueObj( fixture.text() ) ); fixture.html( valueObj( fixture.text() ) );
@ -1810,10 +1810,10 @@ QUnit[
$fixture.html( $fixture.html(
[ [
"<script type='module'>ok( true, 'evaluated: module' );</script>", "<script type='module'>QUnit.assert.ok( true, 'evaluated: module' );</script>",
"<script type='module' src='" + url( "module.js" ) + "'></script>", "<script type='module' src='" + url( "module.js" ) + "'></script>",
"<div>", "<div>",
"<script type='module'>ok( true, 'evaluated: inner module' );</script>", "<script type='module'>QUnit.assert.ok( true, 'evaluated: inner module' );</script>",
"<script type='module' src='" + url( "inner_module.js" ) + "'></script>", "<script type='module' src='" + url( "inner_module.js" ) + "'></script>",
"</div>" "</div>"
].join( "" ) ].join( "" )
@ -2273,7 +2273,7 @@ QUnit.test( "domManip executes scripts containing html comments or CDATA (trac-9
jQuery( [ jQuery( [
"<script type='text/javascript'>", "<script type='text/javascript'>",
"<!--", "<!--",
"ok( true, '<!-- handled' );", "QUnit.assert.ok( true, '<!-- handled' );",
"//-->", "//-->",
"</script>" "</script>"
].join( "\n" ) ).appendTo( "#qunit-fixture" ); ].join( "\n" ) ).appendTo( "#qunit-fixture" );
@ -2281,7 +2281,7 @@ QUnit.test( "domManip executes scripts containing html comments or CDATA (trac-9
jQuery( [ jQuery( [
"<script type='text/javascript'>", "<script type='text/javascript'>",
"<![CDATA[", "<![CDATA[",
"ok( true, '<![CDATA[ handled' );", "QUnit.assert.ok( true, '<![CDATA[ handled' );",
"//]]>", "//]]>",
"</script>" "</script>"
].join( "\n" ) ).appendTo( "#qunit-fixture" ); ].join( "\n" ) ).appendTo( "#qunit-fixture" );
@ -2289,7 +2289,7 @@ QUnit.test( "domManip executes scripts containing html comments or CDATA (trac-9
jQuery( [ jQuery( [
"<script type='text/javascript'>", "<script type='text/javascript'>",
"<!--//--><![CDATA[//><!--", "<!--//--><![CDATA[//><!--",
"ok( true, '<!--//--><![CDATA[//><!-- (Drupal case) handled' );", "QUnit.assert.ok( true, '<!--//--><![CDATA[//><!-- (Drupal case) handled' );",
"//--><!]]>", "//--><!]]>",
"</script>" "</script>"
].join( "\n" ) ).appendTo( "#qunit-fixture" ); ].join( "\n" ) ).appendTo( "#qunit-fixture" );
@ -2418,13 +2418,15 @@ QUnit.test( "Ensure oldIE creates a new set on appendTo (#8894)", function( asse
assert.strictEqual( jQuery( "<p/>" ).appendTo( "<div/>" ).end().length, jQuery( "<p>test</p>" ).appendTo( "<div/>" ).end().length, "Elements created with createElement and with createDocumentFragment should be treated alike" ); assert.strictEqual( jQuery( "<p/>" ).appendTo( "<div/>" ).end().length, jQuery( "<p>test</p>" ).appendTo( "<div/>" ).end().length, "Elements created with createElement and with createDocumentFragment should be treated alike" );
} ); } );
QUnit.asyncTest( "html() - script exceptions bubble (#11743)", 2, function( assert ) { QUnit.test( "html() - script exceptions bubble (#11743)", function( assert ) {
var onerror = window.onerror; assert.expect( 2 );
var done = assert.async(),
onerror = window.onerror;
setTimeout( function() { setTimeout( function() {
window.onerror = onerror; window.onerror = onerror;
QUnit.start(); done();
}, 1000 ); }, 1000 );
window.onerror = function() { window.onerror = function() {
@ -2493,15 +2495,15 @@ QUnit.test( "script evaluation (#11795)", function( assert ) {
objGlobal.ok = notOk; objGlobal.ok = notOk;
scriptsIn = jQuery( [ scriptsIn = jQuery( [
"<script type='something/else'>ok( false, 'evaluated: non-script' );</script>", "<script type='something/else'>QUnit.assert.ok( false, 'evaluated: non-script' );</script>",
"<script type='text/javascript'>ok( true, 'evaluated: text/javascript' );</script>", "<script type='text/javascript'>QUnit.assert.ok( true, 'evaluated: text/javascript' );</script>",
"<script type='text/ecmascript'>ok( true, 'evaluated: text/ecmascript' );</script>", "<script type='text/ecmascript'>QUnit.assert.ok( true, 'evaluated: text/ecmascript' );</script>",
"<script>ok( true, 'evaluated: no type' );</script>", "<script>QUnit.assert.ok( true, 'evaluated: no type' );</script>",
"<div>", "<div>",
"<script type='something/else'>ok( false, 'evaluated: inner non-script' );</script>", "<script type='something/else'>QUnit.assert.ok( false, 'evaluated: inner non-script' );</script>",
"<script type='text/javascript'>ok( true, 'evaluated: inner text/javascript' );</script>", "<script type='text/javascript'>QUnit.assert.ok( true, 'evaluated: inner text/javascript' );</script>",
"<script type='text/ecmascript'>ok( true, 'evaluated: inner text/ecmascript' );</script>", "<script type='text/ecmascript'>QUnit.assert.ok( true, 'evaluated: inner text/ecmascript' );</script>",
"<script>ok( true, 'evaluated: inner no type' );</script>", "<script>QUnit.assert.ok( true, 'evaluated: inner no type' );</script>",
"</div>" "</div>"
].join( "" ) ); ].join( "" ) );
scriptsIn.appendTo( jQuery( "<div class='detached'/>" ) ); scriptsIn.appendTo( jQuery( "<div class='detached'/>" ) );
@ -2823,7 +2825,8 @@ QUnit.test( "Make sure tags with single-character names are found (gh-4124)", fu
assert.strictEqual( htmlOut, htmlIn ); assert.strictEqual( htmlOut, htmlIn );
} ); } );
QUnit.test( "Insert script with data-URI (gh-1887)", 1, function( assert ) { QUnit.test( "Insert script with data-URI (gh-1887)", function( assert ) {
assert.expect( 1 );
Globals.register( "testFoo" ); Globals.register( "testFoo" );
Globals.register( "testSrcFoo" ); Globals.register( "testSrcFoo" );
@ -2849,7 +2852,9 @@ QUnit.test( "Insert script with data-URI (gh-1887)", 1, function( assert ) {
}, 100 ); }, 100 );
} ); } );
QUnit.test( "Ignore content from unsuccessful responses (gh-4126)", 1, function( assert ) { QUnit.test( "Ignore content from unsuccessful responses (gh-4126)", function( assert ) {
assert.expect( 1 );
var globalEval = jQuery.globalEval; var globalEval = jQuery.globalEval;
jQuery.globalEval = function( code ) { jQuery.globalEval = function( code ) {
assert.ok( false, "no attempt to evaluate code from an unsuccessful response" ); assert.ok( false, "no attempt to evaluate code from an unsuccessful response" );

View File

@ -46,7 +46,7 @@ var supportsFixedPosition, supportsScroll, alwaysScrollable,
); );
}; };
QUnit.module( "offset", { setup: function( assert ) { QUnit.module( "offset", { beforeEach: function( assert ) {
if ( typeof checkSupport === "function" ) { if ( typeof checkSupport === "function" ) {
checkSupport( assert ); checkSupport( assert );
} }
@ -56,7 +56,7 @@ QUnit.module( "offset", { setup: function( assert ) {
forceScroll.appendTo( "body" ); forceScroll.appendTo( "body" );
window.scrollTo( 1, 1 ); window.scrollTo( 1, 1 );
forceScroll.detach(); forceScroll.detach();
}, teardown: moduleTeardown } ); }, afterEach: moduleTeardown } );
QUnit.test( "empty set", function( assert ) { QUnit.test( "empty set", function( assert ) {
assert.expect( 2 ); assert.expect( 2 );

View File

@ -1,9 +1,9 @@
QUnit.module( "queue", { teardown: moduleTeardown } ); QUnit.module( "queue", { afterEach: moduleTeardown } );
QUnit.test( "queue() with other types", function( assert ) { QUnit.test( "queue() with other types", function( assert ) {
var done = assert.async( 2 );
assert.expect( 14 ); assert.expect( 14 );
QUnit.stop();
var $div = jQuery( {} ), var $div = jQuery( {} ),
counter = 0; counter = 0;
@ -30,7 +30,7 @@ QUnit.test( "queue() with other types", function( assert ) {
$div.promise( "foo" ).done( function() { $div.promise( "foo" ).done( function() {
assert.equal( counter, 4, "Testing previous call to dequeue in deferred" ); assert.equal( counter, 4, "Testing previous call to dequeue in deferred" );
QUnit.start(); done();
} ); } );
assert.equal( $div.queue( "foo" ).length, 4, "Testing queue length" ); assert.equal( $div.queue( "foo" ).length, 4, "Testing queue length" );
@ -51,7 +51,7 @@ QUnit.test( "queue() with other types", function( assert ) {
assert.equal( counter, 4, "Testing previous call to dequeue" ); assert.equal( counter, 4, "Testing previous call to dequeue" );
assert.equal( $div.queue( "foo" ).length, 0, "Testing queue length" ); assert.equal( $div.queue( "foo" ).length, 0, "Testing queue length" );
done();
} ); } );
QUnit.test( "queue(name) passes in the next item in the queue as a parameter", function( assert ) { QUnit.test( "queue(name) passes in the next item in the queue as a parameter", function( assert ) {
@ -74,8 +74,8 @@ QUnit.test( "queue(name) passes in the next item in the queue as a parameter", f
} ); } );
QUnit.test( "queue() passes in the next item in the queue as a parameter to fx queues", function( assert ) { QUnit.test( "queue() passes in the next item in the queue as a parameter to fx queues", function( assert ) {
var done = assert.async();
assert.expect( 3 ); assert.expect( 3 );
QUnit.stop();
var div = jQuery( {} ), var div = jQuery( {} ),
counter = 0; counter = 0;
@ -92,13 +92,13 @@ QUnit.test( "queue() passes in the next item in the queue as a parameter to fx q
jQuery.when( div.promise( "fx" ), div ).done( function() { jQuery.when( div.promise( "fx" ), div ).done( function() {
assert.equal( counter, 2, "Deferreds resolved" ); assert.equal( counter, 2, "Deferreds resolved" );
QUnit.start(); done();
} ); } );
} ); } );
QUnit.test( "callbacks keep their place in the queue", function( assert ) { QUnit.test( "callbacks keep their place in the queue", function( assert ) {
var done = assert.async();
assert.expect( 5 ); assert.expect( 5 );
QUnit.stop();
var div = jQuery( "<div>" ), var div = jQuery( "<div>" ),
counter = 0; counter = 0;
@ -119,7 +119,7 @@ QUnit.test( "callbacks keep their place in the queue", function( assert ) {
div.promise( "fx" ).done( function() { div.promise( "fx" ).done( function() {
assert.equal( counter, 4, "Deferreds resolved" ); assert.equal( counter, 4, "Deferreds resolved" );
QUnit.start(); done();
} ); } );
} ); } );
@ -132,25 +132,24 @@ QUnit.test( "jQuery.queue should return array while manipulating the queue", fun
} ); } );
QUnit.test( "delay()", function( assert ) { QUnit.test( "delay()", function( assert ) {
var done = assert.async();
assert.expect( 2 ); assert.expect( 2 );
QUnit.stop();
var foo = jQuery( {} ), run = 0; var foo = jQuery( {} ), run = 0;
foo.delay( 100 ).queue( function() { foo.delay( 100 ).queue( function() {
run = 1; run = 1;
assert.ok( true, "The function was dequeued." ); assert.ok( true, "The function was dequeued." );
QUnit.start(); done();
} ); } );
assert.equal( run, 0, "The delay delayed the next function from running." ); assert.equal( run, 0, "The delay delayed the next function from running." );
} ); } );
QUnit.test( "clearQueue(name) clears the queue", function( assert ) { QUnit.test( "clearQueue(name) clears the queue", function( assert ) {
var done = assert.async( 2 );
assert.expect( 2 ); assert.expect( 2 );
QUnit.stop();
var div = jQuery( {} ), var div = jQuery( {} ),
counter = 0; counter = 0;
@ -164,12 +163,13 @@ QUnit.test( "clearQueue(name) clears the queue", function( assert ) {
div.promise( "foo" ).done( function() { div.promise( "foo" ).done( function() {
assert.ok( true, "dequeue resolves the deferred" ); assert.ok( true, "dequeue resolves the deferred" );
QUnit.start(); done();
} ); } );
div.dequeue( "foo" ); div.dequeue( "foo" );
assert.equal( counter, 1, "the queue was cleared" ); assert.equal( counter, 1, "the queue was cleared" );
done();
} ); } );
QUnit.test( "clearQueue() clears the fx queue", function( assert ) { QUnit.test( "clearQueue() clears the fx queue", function( assert ) {
@ -191,9 +191,11 @@ QUnit.test( "clearQueue() clears the fx queue", function( assert ) {
div.removeData(); div.removeData();
} ); } );
QUnit.asyncTest( "fn.promise() - called when fx queue is empty", 3, function( assert ) { QUnit.test( "fn.promise() - called when fx queue is empty", function( assert ) {
assert.expect( 3 );
var foo = jQuery( "#foo" ).clone().addBack(), var foo = jQuery( "#foo" ).clone().addBack(),
promised = false; promised = false,
done = assert.async();
foo.queue( function( next ) { foo.queue( function( next ) {
@ -203,11 +205,13 @@ QUnit.asyncTest( "fn.promise() - called when fx queue is empty", 3, function( as
} ); } );
foo.promise().done( function() { foo.promise().done( function() {
assert.ok( promised = true, "Promised" ); assert.ok( promised = true, "Promised" );
QUnit.start(); done();
} ); } );
} ); } );
QUnit.asyncTest( "fn.promise( \"queue\" ) - called whenever last queue function is dequeued", 5, function( assert ) { QUnit.test( "fn.promise( \"queue\" ) - called whenever last queue function is dequeued", function( assert ) {
assert.expect( 5 );
var done = assert.async();
var foo = jQuery( "#foo" ), var foo = jQuery( "#foo" ),
test; test;
foo.promise( "queue" ).done( function() { foo.promise( "queue" ).done( function() {
@ -222,7 +226,7 @@ QUnit.asyncTest( "fn.promise( \"queue\" ) - called whenever last queue function
setTimeout( function() { setTimeout( function() {
next(); next();
assert.strictEqual( test++, 4, "step four" ); assert.strictEqual( test++, 4, "step four" );
QUnit.start(); done();
}, 10 ); }, 10 );
} ).promise( "queue" ).done( function() { } ).promise( "queue" ).done( function() {
assert.strictEqual( test++, 3, "step three" ); assert.strictEqual( test++, 3, "step three" );
@ -233,7 +237,9 @@ QUnit.asyncTest( "fn.promise( \"queue\" ) - called whenever last queue function
if ( jQuery.fn.animate ) { if ( jQuery.fn.animate ) {
QUnit.asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete before resolving", 2, function( assert ) { QUnit.test( "fn.promise( \"queue\" ) - waits for animation to complete before resolving", function( assert ) {
assert.expect( 2 );
var done = assert.async();
var foo = jQuery( "#foo" ), var foo = jQuery( "#foo" ),
test = 1; test = 1;
@ -249,7 +255,7 @@ QUnit.asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete befo
foo.promise( "queue" ).done( function() { foo.promise( "queue" ).done( function() {
assert.strictEqual( test++, 2, "step two" ); assert.strictEqual( test++, 2, "step two" );
QUnit.start(); done();
} ); } );
} ); } );
@ -267,19 +273,18 @@ QUnit.test( ".promise(obj)", function( assert ) {
if ( jQuery.fn.stop ) { if ( jQuery.fn.stop ) {
QUnit.test( "delay() can be stopped", function( assert ) { QUnit.test( "delay() can be stopped", function( assert ) {
var done = assert.async();
assert.expect( 3 ); assert.expect( 3 );
QUnit.stop(); var storage = {};
var done = {};
jQuery( {} ) jQuery( {} )
.queue( "alternate", function( next ) { .queue( "alternate", function( next ) {
done.alt1 = true; storage.alt1 = true;
assert.ok( true, "This first function was dequeued" ); assert.ok( true, "This first function was dequeued" );
next(); next();
} ) } )
.delay( 1000, "alternate" ) .delay( 1000, "alternate" )
.queue( "alternate", function() { .queue( "alternate", function() {
done.alt2 = true; storage.alt2 = true;
assert.ok( true, "The function was dequeued immediately, the delay was stopped" ); assert.ok( true, "The function was dequeued immediately, the delay was stopped" );
} ) } )
.dequeue( "alternate" ) .dequeue( "alternate" )
@ -290,21 +295,23 @@ if ( jQuery.fn.stop ) {
// this test // this test
.delay( 1 ) .delay( 1 )
.queue( function() { .queue( function() {
done.default1 = true; storage.default1 = true;
assert.ok( false, "This queue should never run" ); assert.ok( false, "This queue should never run" );
} ) } )
// stop( clearQueue ) should clear the queue // stop( clearQueue ) should clear the queue
.stop( true, false ); .stop( true, false );
assert.deepEqual( done, { alt1: true, alt2: true }, "Queue ran the proper functions" ); assert.deepEqual( storage, { alt1: true, alt2: true }, "Queue ran the proper functions" );
setTimeout( function() { setTimeout( function() {
QUnit.start(); done();
}, 1500 ); }, 1500 );
} ); } );
QUnit.asyncTest( "queue stop hooks", 2, function( assert ) { QUnit.test( "queue stop hooks", function( assert ) {
assert.expect( 2 );
var done = assert.async();
var foo = jQuery( "#foo" ); var foo = jQuery( "#foo" );
foo.queue( function( next, hooks ) { foo.queue( function( next, hooks ) {
@ -317,7 +324,7 @@ if ( jQuery.fn.stop ) {
foo.queue( function( next, hooks ) { foo.queue( function( next, hooks ) {
hooks.stop = function( gotoEnd ) { hooks.stop = function( gotoEnd ) {
assert.equal( gotoEnd, true, "Stopped with gotoEnd" ); assert.equal( gotoEnd, true, "Stopped with gotoEnd" );
QUnit.start(); done();
}; };
} ); } );

View File

@ -1,4 +1,4 @@
QUnit.module( "selector", { teardown: moduleTeardown } ); QUnit.module( "selector", { afterEach: moduleTeardown } );
/** /**
* This test page is for selector tests that require jQuery in order to do the selection * This test page is for selector tests that require jQuery in order to do the selection
@ -503,11 +503,13 @@ testIframe(
} }
); );
QUnit.asyncTest( "Iframe dispatch should not affect jQuery (#13936)", 1, function( assert ) { QUnit.test( "Iframe dispatch should not affect jQuery (#13936)", function( assert ) {
assert.expect( 1 );
var loaded = false, var loaded = false,
thrown = false, thrown = false,
iframe = document.getElementById( "iframe" ), iframe = document.getElementById( "iframe" ),
iframeDoc = iframe.contentDocument || iframe.contentWindow.document; iframeDoc = iframe.contentDocument || iframe.contentWindow.document,
done = assert.async();
jQuery( iframe ).on( "load", function() { jQuery( iframe ).on( "load", function() {
var form; var form;
@ -525,7 +527,7 @@ QUnit.asyncTest( "Iframe dispatch should not affect jQuery (#13936)", 1, functio
// clean up // clean up
jQuery( iframe ).off(); jQuery( iframe ).off();
QUnit.start(); done();
} else { } else {
loaded = true; loaded = true;
form.submit(); form.submit();

View File

@ -1,4 +1,4 @@
QUnit.module( "serialize", { teardown: moduleTeardown } ); QUnit.module( "serialize", { afterEach: moduleTeardown } );
QUnit.test( "jQuery.param()", function( assert ) { QUnit.test( "jQuery.param()", function( assert ) {
assert.expect( 24 ); assert.expect( 24 );

View File

@ -1,4 +1,4 @@
QUnit.module( "support", { teardown: moduleTeardown } ); QUnit.module( "support", { afterEach: moduleTeardown } );
var computedSupport = getComputedSupport( jQuery.support ); var computedSupport = getComputedSupport( jQuery.support );

View File

@ -1,4 +1,4 @@
QUnit.module( "traversing", { teardown: moduleTeardown } ); QUnit.module( "traversing", { afterEach: moduleTeardown } );
QUnit.test( "find(String)", function( assert ) { QUnit.test( "find(String)", function( assert ) {
assert.expect( 1 ); assert.expect( 1 );

View File

@ -8,7 +8,7 @@ if ( !jQuery.fx ) {
var oldRaf = window.requestAnimationFrame; var oldRaf = window.requestAnimationFrame;
QUnit.module( "tween", { QUnit.module( "tween", {
setup: function() { beforeEach: function() {
window.requestAnimationFrame = null; window.requestAnimationFrame = null;
this.sandbox = sinon.sandbox.create(); this.sandbox = sinon.sandbox.create();
this.clock = this.sandbox.useFakeTimers( 505877050 ); this.clock = this.sandbox.useFakeTimers( 505877050 );
@ -16,7 +16,7 @@ QUnit.module( "tween", {
jQuery.fx.step = {}; jQuery.fx.step = {};
jQuery.fx.interval = 10; jQuery.fx.interval = 10;
}, },
teardown: function() { afterEach: function() {
this.sandbox.restore(); this.sandbox.restore();
jQuery.fx.stop(); jQuery.fx.stop();
jQuery.fx.interval = this._oldInterval; jQuery.fx.interval = this._oldInterval;
@ -78,7 +78,7 @@ QUnit.test( "jQuery.Tween - Default propHooks on elements", function( assert ) {
fakeTween.prop = "testOpti"; fakeTween.prop = "testOpti";
testElement.testOpti = 15; testElement.testOpti = 15;
cssStub.reset(); cssStub.resetHistory();
assert.equal( defaultHook.get( fakeTween ), 15, "Gets expected value not defined on style" ); assert.equal( defaultHook.get( fakeTween ), 15, "Gets expected value not defined on style" );
assert.equal( cssStub.callCount, 0, "Did not call jQuery.css" ); assert.equal( cssStub.callCount, 0, "Did not call jQuery.css" );
@ -99,7 +99,7 @@ QUnit.test( "jQuery.Tween - Default propHooks on elements", function( assert ) {
cssStub.returns( undefined ); cssStub.returns( undefined );
assert.equal( defaultHook.get( fakeTween ), 0, "Uses 0 for undefined" ); assert.equal( defaultHook.get( fakeTween ), 0, "Uses 0 for undefined" );
cssStub.reset(); cssStub.resetHistory();
// Setters // Setters
styleStub = this.sandbox.stub( jQuery, "style" ); styleStub = this.sandbox.stub( jQuery, "style" );
@ -109,7 +109,7 @@ QUnit.test( "jQuery.Tween - Default propHooks on elements", function( assert ) {
assert.ok( styleStub.calledWith( testElement, "height", "10px" ), assert.ok( styleStub.calledWith( testElement, "height", "10px" ),
"Calls jQuery.style with elem, prop, now+unit" ); "Calls jQuery.style with elem, prop, now+unit" );
styleStub.reset(); styleStub.resetHistory();
fakeTween.prop = "testMissing"; fakeTween.prop = "testMissing";
defaultHook.set( fakeTween ); defaultHook.set( fakeTween );
@ -127,7 +127,7 @@ QUnit.test( "jQuery.Tween - Default propHooks on elements", function( assert ) {
assert.equal( testElement.testMissing, 10, "And value was unchanged" ); assert.equal( testElement.testMissing, 10, "And value was unchanged" );
stepSpy = jQuery.fx.step.test = this.sandbox.spy(); stepSpy = jQuery.fx.step.test = this.sandbox.spy();
styleStub.reset(); styleStub.resetHistory();
fakeTween.prop = "test"; fakeTween.prop = "test";
defaultHook.set( fakeTween ); defaultHook.set( fakeTween );

View File

@ -5,7 +5,7 @@ if ( !jQuery.fn.wrap ) { // no wrap module
} }
QUnit.module( "wrap", { QUnit.module( "wrap", {
teardown: moduleTeardown afterEach: moduleTeardown
} ); } );
// See test/unit/manipulation.js for explanation about these 2 functions // See test/unit/manipulation.js for explanation about these 2 functions
@ -522,7 +522,7 @@ QUnit.test( "wrapping scripts (#10470)", function( assert ) {
var script = document.createElement( "script" ); var script = document.createElement( "script" );
script.text = script.textContent = script.text = script.textContent =
"ok( !document.eval10470, 'script evaluated once' ); document.eval10470 = true;"; "QUnit.assert.ok( !document.eval10470, 'script evaluated once' ); document.eval10470 = true;";
document.eval10470 = false; document.eval10470 = false;
jQuery( "#qunit-fixture" ).empty()[ 0 ].appendChild( script ); jQuery( "#qunit-fixture" ).empty()[ 0 ].appendChild( script );