Tests: further improvements QUnit 2.0 migration

* Remove QUnit jshint globals
* Extend QUnit.assert methods
* Use assert.async instead of start/stop/done

Ref b930d14ce6
Ref c8d15a2f9f
This commit is contained in:
Oleg Gaidarenko
2015-09-08 03:26:29 +03:00
parent f71e32d4b4
commit 2f0cedc997
16 changed files with 284 additions and 262 deletions

View File

@@ -38,7 +38,7 @@ this.q = function() {
* @example t("Check for something", "//[a]", ["foo", "baar"]);
* @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baar'
*/
this.t = function( a, b, c ) {
QUnit.assert.t = function( a, b, c ) {
var f = jQuery( b ).get(),
s = "",
i = 0;
@@ -47,7 +47,7 @@ this.t = function( a, b, c ) {
s += ( s && "," ) + '"' + f[ i ].id + '"';
}
deepEqual( f, q.apply( q, c ), a + " (" + b + ")" );
this.deepEqual( f, q.apply( q, c ), a + " (" + b + ")" );
};
this.createDashboardXML = function() {
@@ -199,7 +199,7 @@ this.ajaxTest = function( title, expect, options ) {
if ( !completed ) {
completed = true;
delete ajaxTest.abort;
ok( false, "aborted " + reason );
assert.ok( false, "aborted " + reason );
jQuery.each( requests, function( i, request ) {
request.abort();
} );

View File

@@ -43,7 +43,7 @@ function keys( o ) {
* @param {jQuery|HTMLElement|Object|Array} elems Target (or array of targets) for jQuery.data.
* @param {string} key
*/
QUnit.expectJqData = function( env, elems, key ) {
QUnit.assert.expectJqData = function( env, elems, key ) {
var i, elem, expando;
// As of jQuery 2.0, there will be no "cache"-data is
@@ -83,7 +83,7 @@ QUnit.expectJqData = function( env, elems, key ) {
// Since this method was called it means some data was
// expected to be found, but since there is nothing, fail early
// (instead of in teardown).
notStrictEqual(
this.notStrictEqual(
expando,
undefined,
"Target for expectJqData must have an expando, " +
@@ -111,7 +111,7 @@ QUnit.config.urlConfig.push( {
* Ensures that tests have cleaned up properly after themselves. Should be passed as the
* teardown function on all modules' lifecycle object.
*/
window.moduleTeardown = function() {
window.moduleTeardown = function( assert ) {
var i,
expectedKeys, actualKeys,
cacheLength = 0;
@@ -123,7 +123,7 @@ window.moduleTeardown = function() {
expectedKeys = expectedDataKeys[ i ];
actualKeys = jQuery.cache[ i ] ? keys( jQuery.cache[ i ] ) : jQuery.cache[ i ];
if ( !QUnit.equiv( expectedKeys, actualKeys ) ) {
deepEqual( actualKeys, expectedKeys, "Expected keys exist in jQuery.cache" );
assert.deepEqual( actualKeys, expectedKeys, "Expected keys exist in jQuery.cache" );
}
delete jQuery.cache[ i ];
delete expectedDataKeys[ i ];
@@ -131,7 +131,7 @@ window.moduleTeardown = function() {
// In case it was removed from cache before (or never there in the first place)
for ( i in expectedDataKeys ) {
deepEqual(
assert.deepEqual(
expectedDataKeys[ i ],
undefined,
"No unexpected keys were left in jQuery.cache (#" + i + ")"
@@ -145,12 +145,12 @@ window.moduleTeardown = function() {
// Check for (and clean up, if possible) incomplete animations/requests/etc.
if ( jQuery.timers && jQuery.timers.length !== 0 ) {
equal( jQuery.timers.length, 0, "No timers are still running" );
assert.equal( jQuery.timers.length, 0, "No timers are still running" );
splice.call( jQuery.timers, 0, jQuery.timers.length );
jQuery.fx.stop();
}
if ( jQuery.active !== undefined && jQuery.active !== oldActive ) {
equal( jQuery.active, oldActive, "No AJAX requests are still active" );
assert.equal( jQuery.active, oldActive, "No AJAX requests are still active" );
if ( ajaxTest.abort ) {
ajaxTest.abort( "active requests" );
}
@@ -168,7 +168,7 @@ window.moduleTeardown = function() {
// if we unconditionally assert any of these,
// the test will fail with too many assertions :|
if ( cacheLength !== oldCacheLength ) {
equal( cacheLength, oldCacheLength, "No unit tests leak memory in jQuery.cache" );
assert.equal( cacheLength, oldCacheLength, "No unit tests leak memory in jQuery.cache" );
oldCacheLength = cacheLength;
}
};