Skip to content

Commit

Permalink
Tests: Remove obsolete jQuery data tests
Browse files Browse the repository at this point in the history
The tests relied on `jQuery.cache` so they only ever worked in jQuery 1.x.

Closes gh-4586

(cherry picked from commit eb35be5)
  • Loading branch information
mgol committed May 18, 2020
1 parent db43ef0 commit 8ad78cd
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 115 deletions.
92 changes: 0 additions & 92 deletions test/data/testrunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,74 +19,6 @@ QUnit.config.testTimeout = 60e3; // 1 minute
// Enforce an "expect" argument or expect() call in all test bodies.
QUnit.config.requireExpects = true;

/**
* @param {jQuery|HTMLElement|Object|Array} elems Target (or array of targets) for jQuery.data.
* @param {string} key
*/
QUnit.assert.expectJqData = function( env, elems, key ) {
var i, elem, expando;

// As of jQuery 2.0, there will be no "cache"-data is
// stored and managed completely below the API surface
if ( jQuery.cache ) {
env.checkJqData = true;

if ( elems.jquery && elems.toArray ) {
elems = elems.toArray();
}
if ( !Array.isArray( elems ) ) {
elems = [ elems ];
}

for ( i = 0; i < elems.length; i++ ) {
elem = elems[ i ];

// jQuery.data only stores data for nodes in jQuery.cache,
// for other data targets the data is stored in the object itself,
// in that case we can't test that target for memory leaks.
// But we don't have to since in that case the data will/must will
// be available as long as the object is not garbage collected by
// the js engine, and when it is, the data will be removed with it.
if ( !elem.nodeType ) {

// Fixes false positives for dataTests(window), dataTests({}).
continue;
}

expando = elem[ jQuery.expando ];

if ( expando === undefined ) {

// In this case the element exists fine, but
// jQuery.data (or internal data) was never (in)directly
// called.
// 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).
this.notStrictEqual(
expando,
undefined,
"Target for expectJqData must have an expando, " +
"for else there can be no data to expect."
);
} else {
if ( expectedDataKeys[ expando ] ) {
expectedDataKeys[ expando ].push( key );
} else {
expectedDataKeys[ expando ] = [ key ];
}
}
}
}

};
QUnit.config.urlConfig.push( {
id: "jqdata",
label: "Always check jQuery.data",
tooltip: "Trigger QUnit.expectJqData detection for all tests " +
"instead of just the ones that call it"
} );

/**
* Ensures that tests have cleaned up properly after themselves. Should be passed as the
* teardown function on all modules' lifecycle object.
Expand All @@ -95,30 +27,6 @@ window.moduleTeardown = function( assert ) {
var i, expectedKeys, actualKeys,
cacheLength = 0;

// Only look for jQuery data problems if this test actually
// provided some information to compare against.
if ( QUnit.urlParams.jqdata || this.checkJqData ) {
for ( i in jQuery.cache ) {
expectedKeys = expectedDataKeys[ i ];
actualKeys = jQuery.cache[ i ] ? Object.keys( jQuery.cache[ i ] ) : jQuery.cache[ i ];
if ( !QUnit.equiv( expectedKeys, actualKeys ) ) {
assert.deepEqual( actualKeys, expectedKeys, "Expected keys exist in jQuery.cache" );
}
delete jQuery.cache[ i ];
delete expectedDataKeys[ i ];
}

// In case it was removed from cache before (or never there in the first place)
for ( i in expectedDataKeys ) {
assert.deepEqual(
expectedDataKeys[ i ],
undefined,
"No unexpected keys were left in jQuery.cache (#" + i + ")"
);
delete expectedDataKeys[ i ];
}
}

// Reset data register
expectedDataKeys = {};

Expand Down
4 changes: 0 additions & 4 deletions test/unit/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1430,10 +1430,6 @@ var testToggleClass = function( valueObj, assert ) {
e.toggleClass( false );
e.toggleClass();
assert.ok( e.is( ".testD.testE" ), "Assert class present (restored from data)" );

// Cleanup
e.removeClass( "testD" );
assert.expectJqData( this, e[ 0 ], "__className__" );
};

QUnit.test( "toggleClass(String|boolean|undefined[, boolean])", function( assert ) {
Expand Down
7 changes: 0 additions & 7 deletions test/unit/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ QUnit.test( "jQuery.data(div)", function( assert ) {
var div = document.createElement( "div" );

dataTests( div, assert );

// We stored one key in the private data
// assert that nothing else was put in there, and that that
// one stayed there.
assert.expectJqData( this, div, "foo" );
} );

QUnit.test( "jQuery.data({})", function( assert ) {
Expand All @@ -159,8 +154,6 @@ QUnit.test( "jQuery.data(document)", function( assert ) {
assert.expect( 25 );

dataTests( document, assert );

assert.expectJqData( this, document, "foo" );
} );

QUnit.test( "jQuery.data(<embed>)", function( assert ) {
Expand Down
12 changes: 0 additions & 12 deletions test/unit/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ QUnit.test( "show()", function( assert ) {
assert.ok( pass, "Show with " + name + " does not call animate callback" );
} );

// Tolerate data from show()/hide()
assert.expectJqData( this, div, "olddisplay" );

jQuery(
"<div id='show-tests'>" +
"<div><p><a href='#'></a></p><code></code><pre></pre><span></span></div>" +
Expand Down Expand Up @@ -217,8 +214,6 @@ supportjQuery.each( hideOptions, function( type, setup ) {
} );

clock.tick( 300 );

assert.expectJqData( this, $span, "olddisplay" );
} );

QUnit[
Expand Down Expand Up @@ -252,8 +247,6 @@ supportjQuery.each( hideOptions, function( type, setup ) {
} );

clock.tick( 300 );

assert.expectJqData( this, $shadowChild, "olddisplay" );
} );
} );

Expand Down Expand Up @@ -1171,9 +1164,6 @@ QUnit.test( "interrupt toggle", function( assert ) {

// Save original property value for comparison
jQuery.data( this, "startVal", jQuery( this ).css( prop ) );

// Expect olddisplay data from our .hide() call below
assert.expectJqData( env, this, "olddisplay" );
} );

// Interrupt a hiding toggle
Expand Down Expand Up @@ -1623,8 +1613,6 @@ QUnit.test( "animate should set display for disconnected nodes", function( asser
assert.strictEqual( $divInline.show()[ 0 ].style.display, "inline",
"show() should not change display if it already set" );

assert.expectJqData( env, $divNone[ 0 ], "olddisplay" );

jQuery.each( showMethods, function( name, opt ) {
jQuery.fn[ name ].apply( jQuery( "<div></div>" ), opt.concat( [ function() {
assert.strictEqual( jQuery( this ).css( "display" ), nullParentDisplay,
Expand Down

0 comments on commit 8ad78cd

Please sign in to comment.