2015-08-16 06:59:58 +00:00
|
|
|
QUnit.module( "data", { teardown: moduleTeardown } );
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( "expando", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2010-09-07 16:51:57 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal( jQuery.expando !== undefined, true, "jQuery is exposing the expando" );
|
|
|
|
} );
|
2010-09-07 16:51:57 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "jQuery.data & removeData, expected returns", function( assert ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.expect( 4 );
|
2013-02-13 17:14:20 +00:00
|
|
|
var elem = document.body;
|
2013-02-03 20:27:55 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.equal(
|
2013-02-13 17:14:20 +00:00
|
|
|
jQuery.data( elem, "hello", "world" ), "world",
|
2013-02-03 20:27:55 +00:00
|
|
|
"jQuery.data( elem, key, value ) returns value"
|
|
|
|
);
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.equal(
|
2013-02-13 17:14:20 +00:00
|
|
|
jQuery.data( elem, "hello" ), "world",
|
|
|
|
"jQuery.data( elem, key ) returns value"
|
|
|
|
);
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.deepEqual(
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.data( elem, { goodnight: "moon" } ), { goodnight: "moon" },
|
2013-03-01 01:24:21 +00:00
|
|
|
"jQuery.data( elem, obj ) returns obj"
|
2013-02-13 17:14:20 +00:00
|
|
|
);
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.equal(
|
2013-02-13 17:14:20 +00:00
|
|
|
jQuery.removeData( elem, "hello" ), undefined,
|
2013-02-03 20:27:55 +00:00
|
|
|
"jQuery.removeData( elem, key, value ) returns undefined"
|
|
|
|
);
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2013-02-03 20:27:55 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "jQuery._data & _removeData, expected returns", function( assert ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.expect( 4 );
|
2013-02-13 17:14:20 +00:00
|
|
|
var elem = document.body;
|
2013-02-03 20:27:55 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.equal(
|
2013-02-13 17:14:20 +00:00
|
|
|
jQuery._data( elem, "hello", "world" ), "world",
|
|
|
|
"jQuery._data( elem, key, value ) returns value"
|
2013-02-03 20:27:55 +00:00
|
|
|
);
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.equal(
|
2013-02-13 17:14:20 +00:00
|
|
|
jQuery._data( elem, "hello" ), "world",
|
|
|
|
"jQuery._data( elem, key ) returns value"
|
|
|
|
);
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.deepEqual(
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery._data( elem, { goodnight: "moon" } ), { goodnight: "moon" },
|
2013-02-13 17:14:20 +00:00
|
|
|
"jQuery._data( elem, obj ) returns obj"
|
|
|
|
);
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.equal(
|
2013-02-13 17:14:20 +00:00
|
|
|
jQuery._removeData( elem, "hello" ), undefined,
|
|
|
|
"jQuery._removeData( elem, key, value ) returns undefined"
|
2013-02-03 20:27:55 +00:00
|
|
|
);
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2013-02-03 20:27:55 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "jQuery.hasData no side effects", function( assert ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.expect( 1 );
|
2013-04-01 16:48:30 +00:00
|
|
|
var obj = {};
|
|
|
|
|
|
|
|
jQuery.hasData( obj );
|
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.equal( Object.getOwnPropertyNames( obj ).length, 0,
|
2013-04-01 16:48:30 +00:00
|
|
|
"No data expandos where added when calling jQuery.hasData(o)"
|
|
|
|
);
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2013-04-01 16:48:30 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
function dataTests( elem, assert ) {
|
2013-04-08 22:18:45 +00:00
|
|
|
var dataObj, internalDataObj;
|
2012-10-24 20:47:40 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal( jQuery.data( elem, "foo" ), undefined, "No data exists initially" );
|
|
|
|
assert.strictEqual( jQuery.hasData( elem ), false, "jQuery.hasData agrees no data exists initially" );
|
2010-09-24 20:24:07 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
dataObj = jQuery.data( elem );
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.equal( typeof dataObj, "object", "Calling data with no args gives us a data object reference" );
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.strictEqual( jQuery.data( elem ), dataObj, "Calling jQuery.data returns the same data object when called multiple times" );
|
2010-09-24 20:24:07 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.strictEqual( jQuery.hasData( elem ), false, "jQuery.hasData agrees no data exists even when an empty data obj exists" );
|
2010-09-24 20:24:07 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
dataObj[ "foo" ] = "bar";
|
|
|
|
assert.equal( jQuery.data( elem, "foo" ), "bar", "Data is readable by jQuery.data when set directly on a returned data object" );
|
2010-09-24 20:24:07 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.strictEqual( jQuery.hasData( elem ), true, "jQuery.hasData agrees data exists when data exists" );
|
2010-02-26 17:35:04 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.data( elem, "foo", "baz" );
|
|
|
|
assert.equal( jQuery.data( elem, "foo" ), "baz", "Data can be changed by jQuery.data" );
|
|
|
|
assert.equal( dataObj[ "foo" ], "baz", "Changes made through jQuery.data propagate to referenced data object" );
|
2010-09-07 16:51:57 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.data( elem, "foo", undefined );
|
|
|
|
assert.equal( jQuery.data( elem, "foo" ), "baz", "Data is not unset by passing undefined to jQuery.data" );
|
2010-02-26 17:35:04 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.data( elem, "foo", null );
|
|
|
|
assert.strictEqual( jQuery.data( elem, "foo" ), null, "Setting null using jQuery.data works OK" );
|
2010-09-07 16:51:57 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.data( elem, "foo", "foo1" );
|
2010-09-07 16:51:57 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.data( elem, { "bar": "baz", "boom": "bloz" } );
|
|
|
|
assert.strictEqual( jQuery.data( elem, "foo" ), "foo1", "Passing an object extends the data object instead of replacing it" );
|
|
|
|
assert.equal( jQuery.data( elem, "boom" ), "bloz", "Extending the data object works" );
|
2010-09-07 16:51:57 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery._data( elem, "foo", "foo2", true );
|
|
|
|
assert.equal( jQuery._data( elem, "foo" ), "foo2", "Setting internal data works" );
|
|
|
|
assert.equal( jQuery.data( elem, "foo" ), "foo1", "Setting internal data does not override user data" );
|
2010-09-07 16:51:57 +00:00
|
|
|
|
2012-06-21 19:30:24 +00:00
|
|
|
internalDataObj = jQuery._data( elem );
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.ok( internalDataObj, "Internal data object exists" );
|
|
|
|
assert.notStrictEqual( dataObj, internalDataObj, "Internal data object is not the same as user data object" );
|
2009-12-09 21:16:18 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.strictEqual( elem.boom, undefined, "Data is never stored directly on the object" );
|
2010-02-27 14:49:58 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.removeData( elem, "foo" );
|
|
|
|
assert.strictEqual( jQuery.data( elem, "foo" ), undefined, "jQuery.removeData removes single properties" );
|
2010-02-27 14:49:58 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.removeData( elem );
|
|
|
|
assert.strictEqual( jQuery._data( elem ), internalDataObj, "jQuery.removeData does not remove internal data if it exists" );
|
2010-10-11 21:52:00 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.data( elem, "foo", "foo1" );
|
|
|
|
jQuery._data( elem, "foo", "foo2" );
|
2011-01-09 21:52:33 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal( jQuery.data( elem, "foo" ), "foo1", "(sanity check) Ensure data is set in user data object" );
|
|
|
|
assert.equal( jQuery._data( elem, "foo" ), "foo2", "(sanity check) Ensure data is set in internal data object" );
|
2011-01-09 21:52:33 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.strictEqual( jQuery._data( elem, jQuery.expando ), undefined, "Removing the last item in internal data destroys the internal data object" );
|
2011-01-09 21:52:33 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery._data( elem, "foo", "foo2" );
|
|
|
|
assert.equal( jQuery._data( elem, "foo" ), "foo2", "(sanity check) Ensure data is set in internal data object" );
|
2010-12-22 21:03:01 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.removeData( elem, "foo" );
|
|
|
|
assert.equal( jQuery._data( elem, "foo" ), "foo2", "(sanity check) jQuery.removeData for user data does not remove internal data" );
|
2011-01-09 21:52:33 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( "jQuery.data(div)", function( assert ) {
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 25 );
|
2015-07-29 15:10:04 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
var div = document.createElement( "div" );
|
2011-01-09 21:52:33 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
dataTests( div, assert );
|
Implement expectation test instead of using _removeData. Close gh-997.
* Removed inline usage of QUnit.reset() because it is messing with the
expectation model as reset does .empty() which does a recursive cleanData
on everything in #qunit-fixture, so any expectJqData above .reset() would
fail negatively.
Instead of calling reset inline, either updated the following assertions to
take previous assertions' state into account, or broke the test() up into
2 tests at the point where it would call QUnit.reset.
* After introducing the new memory leak discovery a whole bunch of tests were
failing as they didn't clean up everything. However I didn't (yet) add
QUnit.expectJqData calls all over the place because in most if not all of
these cases it is valid data storage. For example in test "data()", there
will be an internal data key for "parsedAttrs". This particular test isn't
intending to test for memory leaks, so therefor I made the new discovery
system only push failures when the test contains at least 1 call to
QUnit.expectJqData.
When not, we'll assume that whatever data is being stored is acceptable
because the relevant elements still exist in the DOM anyway (QUnit.reset
will remove the elements and clean up the data automatically).
I did add a "Always check jQuery.data" mode in the test suite that will
trigger it everywhere. Maybe one day we'll include a call to everywhere,
but for now I'm keeping the status quo: Only consider data left in storage
to be a problem if the test says so ("opt-in").
* Had to move #fx-tests inside the fixture because ".remove()" test would
otherwise remove stuff permanently and cause random other tests to fail
as "#hide div" would yield an empty collection.
(Why wasn't this in the fixture in the first place?)
As a result moving fx-tests into the fixture a whole bunch of tests failed
that relied on arbitrary stuff about the document-wide or fixture-wide
state (e.g. number of divs etc.). So I had to adjust various tests to
limit their sample data to not be so variable and unlimited...
* Moved out tests for expando cleanup into a separate test.
* Fixed implied global variable 'pass' in effects.js that was causing
"TypeError: boolean is not a function" in *UNRELATED* dimensions.js that
uses a global variable "pass = function () {};" ...
* Removed spurious calls to _removeData. The new test exposed various failures
e.g. where div[0] isn't being assigned any data anyway.
(queue.js and attributes.js toggleClass).
* Removed spurious clean up at the bottom of test() functions that are
already covered by the teardown (calling QUnit.reset or removeClass to
supposedly undo any changes).
* Documented the parentheses-less magic line in toggleClass. It appeared that
it would always keep the current class name if there was any (since the
assignment started with "this.className || ...".
Adding parentheses + spacing is 8 bytes (though only 1 in gzip apparently).
Only added the comment for now, though I prefer clarity with logical
operators, I'd rather not face the yayMinPD[1] in this test-related commit.
* Updated QUnit urlConfig to the new format (raw string is deprecated).
* Clean up odd htmlentities in test titles, QUnit escapes this.
(^\s+test\(.*)(>\;) → $1>
(^\s+test\(.*)(<\;) → $1<
[1] jQuery MinJsGz Release Police Department (do the same, download less)
2012-10-17 08:33:47 +00:00
|
|
|
|
|
|
|
// We stored one key in the private data
|
|
|
|
// assert that nothing else was put in there, and that that
|
|
|
|
// one stayed there.
|
2015-09-08 00:26:29 +00:00
|
|
|
assert.expectJqData( this, div, "foo" );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
Implement expectation test instead of using _removeData. Close gh-997.
* Removed inline usage of QUnit.reset() because it is messing with the
expectation model as reset does .empty() which does a recursive cleanData
on everything in #qunit-fixture, so any expectJqData above .reset() would
fail negatively.
Instead of calling reset inline, either updated the following assertions to
take previous assertions' state into account, or broke the test() up into
2 tests at the point where it would call QUnit.reset.
* After introducing the new memory leak discovery a whole bunch of tests were
failing as they didn't clean up everything. However I didn't (yet) add
QUnit.expectJqData calls all over the place because in most if not all of
these cases it is valid data storage. For example in test "data()", there
will be an internal data key for "parsedAttrs". This particular test isn't
intending to test for memory leaks, so therefor I made the new discovery
system only push failures when the test contains at least 1 call to
QUnit.expectJqData.
When not, we'll assume that whatever data is being stored is acceptable
because the relevant elements still exist in the DOM anyway (QUnit.reset
will remove the elements and clean up the data automatically).
I did add a "Always check jQuery.data" mode in the test suite that will
trigger it everywhere. Maybe one day we'll include a call to everywhere,
but for now I'm keeping the status quo: Only consider data left in storage
to be a problem if the test says so ("opt-in").
* Had to move #fx-tests inside the fixture because ".remove()" test would
otherwise remove stuff permanently and cause random other tests to fail
as "#hide div" would yield an empty collection.
(Why wasn't this in the fixture in the first place?)
As a result moving fx-tests into the fixture a whole bunch of tests failed
that relied on arbitrary stuff about the document-wide or fixture-wide
state (e.g. number of divs etc.). So I had to adjust various tests to
limit their sample data to not be so variable and unlimited...
* Moved out tests for expando cleanup into a separate test.
* Fixed implied global variable 'pass' in effects.js that was causing
"TypeError: boolean is not a function" in *UNRELATED* dimensions.js that
uses a global variable "pass = function () {};" ...
* Removed spurious calls to _removeData. The new test exposed various failures
e.g. where div[0] isn't being assigned any data anyway.
(queue.js and attributes.js toggleClass).
* Removed spurious clean up at the bottom of test() functions that are
already covered by the teardown (calling QUnit.reset or removeClass to
supposedly undo any changes).
* Documented the parentheses-less magic line in toggleClass. It appeared that
it would always keep the current class name if there was any (since the
assignment started with "this.className || ...".
Adding parentheses + spacing is 8 bytes (though only 1 in gzip apparently).
Only added the comment for now, though I prefer clarity with logical
operators, I'd rather not face the yayMinPD[1] in this test-related commit.
* Updated QUnit urlConfig to the new format (raw string is deprecated).
* Clean up odd htmlentities in test titles, QUnit escapes this.
(^\s+test\(.*)(>\;) → $1>
(^\s+test\(.*)(<\;) → $1<
[1] jQuery MinJsGz Release Police Department (do the same, download less)
2012-10-17 08:33:47 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( "jQuery.data({})", function( assert ) {
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 25 );
|
2015-07-29 15:10:04 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
dataTests( {}, assert );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2011-01-09 21:52:33 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( "jQuery.data(window)", function( assert ) {
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 25 );
|
2015-07-29 15:10:04 +00:00
|
|
|
|
2011-01-09 21:52:33 +00:00
|
|
|
// remove bound handlers from window object to stop potential false positives caused by fix for #5280 in
|
|
|
|
// transports/xhr.js
|
2014-11-07 06:30:18 +00:00
|
|
|
jQuery( window ).off( "unload" );
|
2011-01-09 21:52:33 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
dataTests( window, assert );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
Implement expectation test instead of using _removeData. Close gh-997.
* Removed inline usage of QUnit.reset() because it is messing with the
expectation model as reset does .empty() which does a recursive cleanData
on everything in #qunit-fixture, so any expectJqData above .reset() would
fail negatively.
Instead of calling reset inline, either updated the following assertions to
take previous assertions' state into account, or broke the test() up into
2 tests at the point where it would call QUnit.reset.
* After introducing the new memory leak discovery a whole bunch of tests were
failing as they didn't clean up everything. However I didn't (yet) add
QUnit.expectJqData calls all over the place because in most if not all of
these cases it is valid data storage. For example in test "data()", there
will be an internal data key for "parsedAttrs". This particular test isn't
intending to test for memory leaks, so therefor I made the new discovery
system only push failures when the test contains at least 1 call to
QUnit.expectJqData.
When not, we'll assume that whatever data is being stored is acceptable
because the relevant elements still exist in the DOM anyway (QUnit.reset
will remove the elements and clean up the data automatically).
I did add a "Always check jQuery.data" mode in the test suite that will
trigger it everywhere. Maybe one day we'll include a call to everywhere,
but for now I'm keeping the status quo: Only consider data left in storage
to be a problem if the test says so ("opt-in").
* Had to move #fx-tests inside the fixture because ".remove()" test would
otherwise remove stuff permanently and cause random other tests to fail
as "#hide div" would yield an empty collection.
(Why wasn't this in the fixture in the first place?)
As a result moving fx-tests into the fixture a whole bunch of tests failed
that relied on arbitrary stuff about the document-wide or fixture-wide
state (e.g. number of divs etc.). So I had to adjust various tests to
limit their sample data to not be so variable and unlimited...
* Moved out tests for expando cleanup into a separate test.
* Fixed implied global variable 'pass' in effects.js that was causing
"TypeError: boolean is not a function" in *UNRELATED* dimensions.js that
uses a global variable "pass = function () {};" ...
* Removed spurious calls to _removeData. The new test exposed various failures
e.g. where div[0] isn't being assigned any data anyway.
(queue.js and attributes.js toggleClass).
* Removed spurious clean up at the bottom of test() functions that are
already covered by the teardown (calling QUnit.reset or removeClass to
supposedly undo any changes).
* Documented the parentheses-less magic line in toggleClass. It appeared that
it would always keep the current class name if there was any (since the
assignment started with "this.className || ...".
Adding parentheses + spacing is 8 bytes (though only 1 in gzip apparently).
Only added the comment for now, though I prefer clarity with logical
operators, I'd rather not face the yayMinPD[1] in this test-related commit.
* Updated QUnit urlConfig to the new format (raw string is deprecated).
* Clean up odd htmlentities in test titles, QUnit escapes this.
(^\s+test\(.*)(>\;) → $1>
(^\s+test\(.*)(<\;) → $1<
[1] jQuery MinJsGz Release Police Department (do the same, download less)
2012-10-17 08:33:47 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( "jQuery.data(document)", function( assert ) {
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 25 );
|
2015-07-29 15:10:04 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
dataTests( document, assert );
|
2011-01-09 21:52:33 +00:00
|
|
|
|
2015-09-08 00:26:29 +00:00
|
|
|
assert.expectJqData( this, document, "foo" );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
Implement expectation test instead of using _removeData. Close gh-997.
* Removed inline usage of QUnit.reset() because it is messing with the
expectation model as reset does .empty() which does a recursive cleanData
on everything in #qunit-fixture, so any expectJqData above .reset() would
fail negatively.
Instead of calling reset inline, either updated the following assertions to
take previous assertions' state into account, or broke the test() up into
2 tests at the point where it would call QUnit.reset.
* After introducing the new memory leak discovery a whole bunch of tests were
failing as they didn't clean up everything. However I didn't (yet) add
QUnit.expectJqData calls all over the place because in most if not all of
these cases it is valid data storage. For example in test "data()", there
will be an internal data key for "parsedAttrs". This particular test isn't
intending to test for memory leaks, so therefor I made the new discovery
system only push failures when the test contains at least 1 call to
QUnit.expectJqData.
When not, we'll assume that whatever data is being stored is acceptable
because the relevant elements still exist in the DOM anyway (QUnit.reset
will remove the elements and clean up the data automatically).
I did add a "Always check jQuery.data" mode in the test suite that will
trigger it everywhere. Maybe one day we'll include a call to everywhere,
but for now I'm keeping the status quo: Only consider data left in storage
to be a problem if the test says so ("opt-in").
* Had to move #fx-tests inside the fixture because ".remove()" test would
otherwise remove stuff permanently and cause random other tests to fail
as "#hide div" would yield an empty collection.
(Why wasn't this in the fixture in the first place?)
As a result moving fx-tests into the fixture a whole bunch of tests failed
that relied on arbitrary stuff about the document-wide or fixture-wide
state (e.g. number of divs etc.). So I had to adjust various tests to
limit their sample data to not be so variable and unlimited...
* Moved out tests for expando cleanup into a separate test.
* Fixed implied global variable 'pass' in effects.js that was causing
"TypeError: boolean is not a function" in *UNRELATED* dimensions.js that
uses a global variable "pass = function () {};" ...
* Removed spurious calls to _removeData. The new test exposed various failures
e.g. where div[0] isn't being assigned any data anyway.
(queue.js and attributes.js toggleClass).
* Removed spurious clean up at the bottom of test() functions that are
already covered by the teardown (calling QUnit.reset or removeClass to
supposedly undo any changes).
* Documented the parentheses-less magic line in toggleClass. It appeared that
it would always keep the current class name if there was any (since the
assignment started with "this.className || ...".
Adding parentheses + spacing is 8 bytes (though only 1 in gzip apparently).
Only added the comment for now, though I prefer clarity with logical
operators, I'd rather not face the yayMinPD[1] in this test-related commit.
* Updated QUnit urlConfig to the new format (raw string is deprecated).
* Clean up odd htmlentities in test titles, QUnit escapes this.
(^\s+test\(.*)(>\;) → $1>
(^\s+test\(.*)(<\;) → $1<
[1] jQuery MinJsGz Release Police Department (do the same, download less)
2012-10-17 08:33:47 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( "jQuery.data(<embed>)", function( assert ) {
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 25 );
|
2015-07-29 15:10:04 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
dataTests( document.createElement( "embed" ), assert );
|
|
|
|
} );
|
2013-02-11 17:39:44 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( "jQuery.data(object/flash)", function( assert ) {
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 25 );
|
2015-07-29 15:10:04 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
var flash = document.createElement( "object" );
|
2013-02-28 19:14:40 +00:00
|
|
|
flash.setAttribute( "classid", "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" );
|
2013-01-11 15:04:50 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
dataTests( flash, assert );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2011-01-09 21:52:33 +00:00
|
|
|
|
2013-11-05 20:03:28 +00:00
|
|
|
// attempting to access the data of an undefined jQuery element should be undefined
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( "jQuery().data() === undefined (#14101)", function( assert ) {
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 2 );
|
2015-07-29 15:10:04 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.strictEqual( jQuery().data(), undefined );
|
|
|
|
assert.strictEqual( jQuery().data( "key" ), undefined );
|
|
|
|
} );
|
2013-11-05 20:03:28 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( ".data()", function( assert ) {
|
|
|
|
assert.expect( 5 );
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
var div, dataObj, nodiv, obj;
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
div = jQuery( "#foo" );
|
|
|
|
assert.strictEqual( div.data( "foo" ), undefined, "Make sure that missing result is undefined" );
|
|
|
|
div.data( "test", "success" );
|
2011-02-14 22:22:23 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
dataObj = div.data();
|
2011-02-14 22:22:23 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.deepEqual( dataObj, { test: "success" }, "data() returns entire data object with expected properties" );
|
|
|
|
assert.strictEqual( div.data( "foo" ), undefined, "Make sure that missing result is still undefined" );
|
2010-09-07 16:51:57 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
nodiv = jQuery( "#unfound" );
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.equal( nodiv.data(), null, "data() on empty set returns null" );
|
2010-12-03 07:19:39 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
obj = { foo: "bar" };
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery( obj ).data( "foo", "baz" );
|
2011-02-07 16:48:38 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
dataObj = jQuery.extend( true, {}, jQuery( obj ).data() );
|
2011-02-14 22:22:23 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.deepEqual( dataObj, { "foo": "baz" }, "Retrieve data object from a wrapped JS object (#7524)" );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
function testDataTypes( $obj, assert ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.each( {
|
2012-11-06 14:53:00 +00:00
|
|
|
"null": null,
|
|
|
|
"true": true,
|
|
|
|
"false": false,
|
|
|
|
"zero": 0,
|
|
|
|
"one": 1,
|
|
|
|
"empty string": "",
|
|
|
|
"empty array": [],
|
2015-08-16 06:59:58 +00:00
|
|
|
"array": [ 1 ],
|
2012-11-06 14:53:00 +00:00
|
|
|
"empty object": {},
|
|
|
|
"object": { foo: "bar" },
|
|
|
|
"date": new Date(),
|
|
|
|
"regex": /test/,
|
|
|
|
"function": function() {}
|
|
|
|
}, function( type, value ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.strictEqual( $obj.data( "test", value ).data( "test" ), value, "Data set to " + type );
|
|
|
|
} );
|
2013-04-09 15:45:09 +00:00
|
|
|
}
|
2012-11-06 14:53:00 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( "jQuery(Element).data(String, Object).data(String)", function( assert ) {
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 18 );
|
2015-08-16 06:59:58 +00:00
|
|
|
var parent = jQuery( "<div><div></div></div>" ),
|
2010-07-27 17:45:32 +00:00
|
|
|
div = parent.children();
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.strictEqual( div.data( "test" ), undefined, "No data exists initially" );
|
|
|
|
assert.strictEqual( div.data( "test", "success" ).data( "test" ), "success", "Data added" );
|
|
|
|
assert.strictEqual( div.data( "test", "overwritten" ).data( "test" ), "overwritten", "Data overwritten" );
|
|
|
|
assert.strictEqual( div.data( "test", undefined ).data( "test" ), "overwritten", ".data(key,undefined) does nothing but is chainable (#5571)" );
|
|
|
|
assert.strictEqual( div.data( "notexist" ), undefined, "No data exists for unset key" );
|
2015-08-16 03:45:28 +00:00
|
|
|
testDataTypes( div, assert );
|
2010-02-26 17:35:04 +00:00
|
|
|
|
2012-11-06 14:53:00 +00:00
|
|
|
parent.remove();
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( "jQuery(plain Object).data(String, Object).data(String)", function( assert ) {
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 16 );
|
2010-02-26 17:35:04 +00:00
|
|
|
|
2009-11-25 17:09:53 +00:00
|
|
|
// #3748
|
2015-08-16 06:59:58 +00:00
|
|
|
var $obj = jQuery( { exists: true } );
|
|
|
|
assert.strictEqual( $obj.data( "nothing" ), undefined, "Non-existent data returns undefined" );
|
|
|
|
assert.strictEqual( $obj.data( "exists" ), undefined, "Object properties are not returned as data" );
|
2015-08-16 03:45:28 +00:00
|
|
|
testDataTypes( $obj, assert );
|
2010-12-22 20:54:37 +00:00
|
|
|
|
2009-11-25 17:09:53 +00:00
|
|
|
// Clean up
|
2012-11-06 14:53:00 +00:00
|
|
|
$obj.removeData();
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.deepEqual( $obj[ 0 ], { exists: true }, "removeData does not clear the object" );
|
|
|
|
} );
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( ".data(object) does not retain references. #13815", function( assert ) {
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 2 );
|
2013-04-24 20:07:15 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
var $divs = jQuery( "<div></div><div></div>" ).appendTo( "#qunit-fixture" );
|
2013-04-24 20:07:15 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
$divs.data( { "type": "foo" } );
|
2013-04-24 20:07:15 +00:00
|
|
|
$divs.eq( 0 ).data( "type", "bar" );
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal( $divs.eq( 0 ).data( "type" ), "bar", "Correct updated value" );
|
|
|
|
assert.equal( $divs.eq( 1 ).data( "type" ), "foo", "Original value retained" );
|
|
|
|
} );
|
2013-04-24 20:07:15 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( "data-* attributes", function( assert ) {
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 46 );
|
2013-10-11 08:09:54 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
var prop, i, l, metadata, elem,
|
|
|
|
obj, obj2, check, num, num2,
|
2013-10-11 08:09:54 +00:00
|
|
|
parseJSON = jQuery.parseJSON,
|
2015-08-16 06:59:58 +00:00
|
|
|
div = jQuery( "<div>" ),
|
|
|
|
child = jQuery( "<div data-myobj='old data' data-ignored=\"DOM\" data-other='test' data-foo-42='boosh'></div>" ),
|
|
|
|
dummy = jQuery( "<div data-myobj='old data' data-ignored=\"DOM\" data-other='test' data-foo-42='boosh'></div>" );
|
2010-12-22 20:54:37 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal( div.data( "attr" ), undefined, "Check for non-existing data-attr attribute" );
|
2010-09-20 21:47:41 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
div.attr( "data-attr", "exists" );
|
|
|
|
assert.equal( div.data( "attr" ), "exists", "Check for existing data-attr attribute" );
|
2010-10-17 15:42:53 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
div.attr( "data-attr", "exists2" );
|
|
|
|
assert.equal( div.data( "attr" ), "exists", "Check that updates to data- don't update .data()" );
|
2010-12-22 20:54:37 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
div.data( "attr", "internal" ).attr( "data-attr", "external" );
|
|
|
|
assert.equal( div.data( "attr" ), "internal", "Check for .data('attr') precedence (internal > external data-* attribute)" );
|
2010-12-22 20:54:37 +00:00
|
|
|
|
2011-01-09 21:58:47 +00:00
|
|
|
div.remove();
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
child.appendTo( "#qunit-fixture" );
|
|
|
|
assert.equal( child.data( "myobj" ), "old data", "Value accessed from data-* attribute" );
|
|
|
|
assert.equal( child.data( "foo-42" ), "boosh", "camelCasing does not affect numbers (#1751)" );
|
2010-09-20 21:47:41 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
child.data( "myobj", "replaced" );
|
|
|
|
assert.equal( child.data( "myobj" ), "replaced", "Original data overwritten" );
|
2010-09-20 21:47:41 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
child.data( "ignored", "cache" );
|
|
|
|
assert.equal( child.data( "ignored" ), "cache", "Cached data used before DOM data-* fallback" );
|
2010-09-20 21:47:41 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
obj = child.data();
|
|
|
|
obj2 = dummy.data();
|
2015-05-03 12:22:32 +00:00
|
|
|
check = [ "myobj", "ignored", "other", "foo-42" ];
|
2013-04-09 15:45:09 +00:00
|
|
|
num = 0;
|
|
|
|
num2 = 0;
|
2010-10-17 15:42:53 +00:00
|
|
|
|
2011-01-09 21:58:47 +00:00
|
|
|
dummy.remove();
|
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
for ( i = 0, l = check.length; i < l; i++ ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.ok( obj[ check[ i ] ], "Make sure data- property exists when calling data-." );
|
|
|
|
assert.ok( obj2[ check[ i ] ], "Make sure data- property exists when calling data-." );
|
2010-10-17 15:42:53 +00:00
|
|
|
}
|
|
|
|
|
2012-06-21 19:30:24 +00:00
|
|
|
for ( prop in obj ) {
|
2010-10-17 15:42:53 +00:00
|
|
|
num++;
|
|
|
|
}
|
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.equal( num, check.length, "Make sure that the right number of properties came through." );
|
2010-10-17 18:48:24 +00:00
|
|
|
|
2012-06-21 19:30:24 +00:00
|
|
|
for ( prop in obj2 ) {
|
2010-10-17 18:48:24 +00:00
|
|
|
num2++;
|
|
|
|
}
|
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.equal( num2, check.length, "Make sure that the right number of properties came through." );
|
2010-10-17 15:42:53 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
child.attr( "data-other", "newvalue" );
|
2010-10-17 15:42:53 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal( child.data( "other" ), "test", "Make sure value was pulled in properly from a .data()." );
|
2010-10-17 15:42:53 +00:00
|
|
|
|
2013-10-11 08:09:54 +00:00
|
|
|
// attribute parsing
|
2013-10-28 15:35:53 +00:00
|
|
|
i = 0;
|
2013-10-11 08:09:54 +00:00
|
|
|
jQuery.parseJSON = function() {
|
|
|
|
i++;
|
|
|
|
return parseJSON.apply( this, arguments );
|
|
|
|
};
|
|
|
|
|
2010-09-20 21:47:41 +00:00
|
|
|
child
|
2015-08-16 06:59:58 +00:00
|
|
|
.attr( "data-true", "true" )
|
|
|
|
.attr( "data-false", "false" )
|
|
|
|
.attr( "data-five", "5" )
|
|
|
|
.attr( "data-point", "5.5" )
|
|
|
|
.attr( "data-pointe", "5.5E3" )
|
|
|
|
.attr( "data-grande", "5.574E9" )
|
|
|
|
.attr( "data-hexadecimal", "0x42" )
|
|
|
|
.attr( "data-pointbad", "5..5" )
|
|
|
|
.attr( "data-pointbad2", "-." )
|
|
|
|
.attr( "data-bigassnum", "123456789123456789123456789" )
|
|
|
|
.attr( "data-badjson", "{123}" )
|
|
|
|
.attr( "data-badjson2", "[abc]" )
|
|
|
|
.attr( "data-notjson", " {}" )
|
|
|
|
.attr( "data-notjson2", "[] " )
|
|
|
|
.attr( "data-empty", "" )
|
|
|
|
.attr( "data-space", " " )
|
|
|
|
.attr( "data-null", "null" )
|
|
|
|
.attr( "data-string", "test" );
|
|
|
|
|
|
|
|
assert.strictEqual( child.data( "true" ), true, "Primitive true read from attribute" );
|
|
|
|
assert.strictEqual( child.data( "false" ), false, "Primitive false read from attribute" );
|
|
|
|
assert.strictEqual( child.data( "five" ), 5, "Integer read from attribute" );
|
|
|
|
assert.strictEqual( child.data( "point" ), 5.5, "Floating-point number read from attribute" );
|
|
|
|
assert.strictEqual( child.data( "pointe" ), "5.5E3",
|
|
|
|
"Exponential-notation number read from attribute as string" );
|
|
|
|
assert.strictEqual( child.data( "grande" ), "5.574E9",
|
|
|
|
"Big exponential-notation number read from attribute as string" );
|
|
|
|
assert.strictEqual( child.data( "hexadecimal" ), "0x42",
|
|
|
|
"Hexadecimal number read from attribute as string" );
|
|
|
|
assert.strictEqual( child.data( "pointbad" ), "5..5",
|
|
|
|
"Extra-point non-number read from attribute as string" );
|
|
|
|
assert.strictEqual( child.data( "pointbad2" ), "-.",
|
|
|
|
"No-digit non-number read from attribute as string" );
|
|
|
|
assert.strictEqual( child.data( "bigassnum" ), "123456789123456789123456789",
|
|
|
|
"Bad bigass number read from attribute as string" );
|
|
|
|
assert.strictEqual( child.data( "badjson" ), "{123}", "Bad JSON object read from attribute as string" );
|
|
|
|
assert.strictEqual( child.data( "badjson2" ), "[abc]", "Bad JSON array read from attribute as string" );
|
|
|
|
assert.strictEqual( child.data( "notjson" ), " {}",
|
|
|
|
"JSON object with leading non-JSON read from attribute as string" );
|
|
|
|
assert.strictEqual( child.data( "notjson2" ), "[] ",
|
|
|
|
"JSON array with trailing non-JSON read from attribute as string" );
|
|
|
|
assert.strictEqual( child.data( "empty" ), "", "Empty string read from attribute" );
|
|
|
|
assert.strictEqual( child.data( "space" ), " ", "Whitespace string read from attribute" );
|
|
|
|
assert.strictEqual( child.data( "null" ), null, "Primitive null read from attribute" );
|
|
|
|
assert.strictEqual( child.data( "string" ), "test", "Typical string read from attribute" );
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.equal( i, 2, "Correct number of JSON parse attempts when reading from attributes" );
|
2010-09-20 21:47:41 +00:00
|
|
|
|
2013-10-11 08:09:54 +00:00
|
|
|
jQuery.parseJSON = parseJSON;
|
2010-09-20 21:47:41 +00:00
|
|
|
child.remove();
|
2010-12-22 20:54:37 +00:00
|
|
|
|
2010-09-20 21:47:41 +00:00
|
|
|
// tests from metadata plugin
|
2015-08-16 06:59:58 +00:00
|
|
|
function testData( index, elem ) {
|
|
|
|
switch ( index ) {
|
2010-09-20 21:47:41 +00:00
|
|
|
case 0:
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal( jQuery( elem ).data( "foo" ), "bar", "Check foo property" );
|
|
|
|
assert.equal( jQuery( elem ).data( "bar" ), "baz", "Check baz property" );
|
2010-09-20 21:47:41 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal( jQuery( elem ).data( "test" ), "bar", "Check test property" );
|
|
|
|
assert.equal( jQuery( elem ).data( "bar" ), "baz", "Check bar property" );
|
2010-09-20 21:47:41 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal( jQuery( elem ).data( "zoooo" ), "bar", "Check zoooo property" );
|
|
|
|
assert.deepEqual( jQuery( elem ).data( "bar" ), { "test":"baz" }, "Check bar property" );
|
2010-09-20 21:47:41 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal( jQuery( elem ).data( "number" ), true, "Check number property" );
|
|
|
|
assert.deepEqual( jQuery( elem ).data( "stuff" ), [ 2,8 ], "Check stuff property" );
|
2010-09-20 21:47:41 +00:00
|
|
|
break;
|
|
|
|
default:
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.ok( false, [ "Assertion failed on index ", index, ", with data" ].join( "" ) );
|
2010-09-20 21:47:41 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-22 20:54:37 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
metadata = "<ol><li class='test test2' data-foo='bar' data-bar='baz' data-arr='[1,2]'>Some stuff</li><li class='test test2' data-test='bar' data-bar='baz'>Some stuff</li><li class='test test2' data-zoooo='bar' data-bar='{\"test\":\"baz\"}'>Some stuff</li><li class='test test2' data-number=true data-stuff='[2,8]'>Some stuff</li></ol>";
|
2015-08-16 06:59:58 +00:00
|
|
|
elem = jQuery( metadata ).appendTo( "#qunit-fixture" );
|
2010-12-22 20:54:37 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
elem.find( "li" ).each( testData );
|
2010-09-20 21:47:41 +00:00
|
|
|
elem.remove();
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2010-09-20 21:47:41 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( ".data(Object)", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2009-12-09 21:16:18 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
var obj, jqobj,
|
2015-08-16 06:59:58 +00:00
|
|
|
div = jQuery( "<div/>" );
|
2009-12-09 21:16:18 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
div.data( { "test": "in", "test2": "in2" } );
|
|
|
|
assert.equal( div.data( "test" ), "in", "Verify setting an object in data" );
|
|
|
|
assert.equal( div.data( "test2" ), "in2", "Verify setting an object in data" );
|
2010-12-22 20:54:37 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
obj = { test:"unset" };
|
|
|
|
jqobj = jQuery( obj );
|
2013-04-09 15:45:09 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jqobj.data( "test", "unset" );
|
|
|
|
jqobj.data( { "test": "in", "test2": "in2" } );
|
|
|
|
assert.equal( jQuery.data( obj )[ "test" ], "in", "Verify setting an object on an object extends the data object" );
|
|
|
|
assert.equal( obj[ "test2" ], undefined, "Verify setting an object on an object does not extend the object" );
|
2011-01-09 21:52:33 +00:00
|
|
|
|
|
|
|
// manually clean up detached elements
|
|
|
|
div.remove();
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2009-12-09 21:16:18 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( "jQuery.removeData", function( assert ) {
|
|
|
|
assert.expect( 10 );
|
2013-04-09 15:45:09 +00:00
|
|
|
|
|
|
|
var obj,
|
2015-08-16 06:59:58 +00:00
|
|
|
div = jQuery( "#foo" )[ 0 ];
|
|
|
|
jQuery.data( div, "test", "testing" );
|
|
|
|
jQuery.removeData( div, "test" );
|
|
|
|
assert.equal( jQuery.data( div, "test" ), undefined, "Check removal of data" );
|
2010-10-17 14:56:01 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.data( div, "test2", "testing" );
|
2010-10-17 14:56:01 +00:00
|
|
|
jQuery.removeData( div );
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.ok( !jQuery.data( div, "test2" ), "Make sure that the data property no longer exists." );
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.ok( !div[ jQuery.expando ], "Make sure the expando no longer exists, as well." );
|
2010-12-22 20:54:37 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.data( div, {
|
2011-09-20 01:16:20 +00:00
|
|
|
test3: "testing",
|
|
|
|
test4: "testing"
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2011-09-20 01:16:20 +00:00
|
|
|
jQuery.removeData( div, "test3 test4" );
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.ok( !jQuery.data( div, "test3" ) || jQuery.data( div, "test4" ), "Multiple delete with spaces." );
|
2011-09-20 01:16:20 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.data( div, {
|
2011-09-20 01:16:20 +00:00
|
|
|
test3: "testing",
|
|
|
|
test4: "testing"
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2011-09-20 01:16:20 +00:00
|
|
|
jQuery.removeData( div, [ "test3", "test4" ] );
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.ok( !jQuery.data( div, "test3" ) || jQuery.data( div, "test4" ), "Multiple delete by array." );
|
2011-09-20 01:16:20 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.data( div, {
|
2011-09-20 01:16:20 +00:00
|
|
|
"test3 test4": "testing",
|
2012-07-05 19:52:13 +00:00
|
|
|
"test3": "testing"
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2011-09-20 01:16:20 +00:00
|
|
|
jQuery.removeData( div, "test3 test4" );
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.ok( !jQuery.data( div, "test3 test4" ), "Multiple delete with spaces deleted key with exact name" );
|
|
|
|
assert.ok( jQuery.data( div, "test3" ), "Left the partial matched key alone" );
|
2011-09-20 01:16:20 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
obj = {};
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.data( obj, "test", "testing" );
|
|
|
|
assert.equal( jQuery( obj ).data( "test" ), "testing", "verify data on plain object" );
|
|
|
|
jQuery.removeData( obj, "test" );
|
|
|
|
assert.equal( jQuery.data( obj, "test" ), undefined, "Check removal of data on plain object" );
|
2010-10-11 21:52:00 +00:00
|
|
|
|
|
|
|
jQuery.data( window, "BAD", true );
|
|
|
|
jQuery.removeData( window, "BAD" );
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.ok( !jQuery.data( window, "BAD" ), "Make sure that the value was not still set." );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( ".removeData()", function( assert ) {
|
|
|
|
assert.expect( 6 );
|
|
|
|
var div = jQuery( "#foo" );
|
|
|
|
div.data( "test", "testing" );
|
|
|
|
div.removeData( "test" );
|
|
|
|
assert.equal( div.data( "test" ), undefined, "Check removal of data" );
|
|
|
|
|
|
|
|
div.data( "test", "testing" );
|
|
|
|
div.data( "test.foo", "testing2" );
|
|
|
|
div.removeData( "test.bar" );
|
|
|
|
assert.equal( div.data( "test.foo" ), "testing2", "Make sure data is intact" );
|
|
|
|
assert.equal( div.data( "test" ), "testing", "Make sure data is intact" );
|
|
|
|
|
|
|
|
div.removeData( "test" );
|
|
|
|
assert.equal( div.data( "test.foo" ), "testing2", "Make sure data is intact" );
|
|
|
|
assert.equal( div.data( "test" ), undefined, "Make sure data is intact" );
|
|
|
|
|
|
|
|
div.removeData( "test.foo" );
|
|
|
|
assert.equal( div.data( "test.foo" ), undefined, "Make sure data is intact" );
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( window.JSON && window.JSON.stringify ) {
|
|
|
|
QUnit.test( "JSON serialization (#8108)", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2011-02-14 22:22:23 +00:00
|
|
|
|
2012-07-05 19:52:13 +00:00
|
|
|
var obj = { "foo": "bar" };
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.data( obj, "hidden", true );
|
2011-02-14 22:22:23 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal( JSON.stringify( obj ), "{\"foo\":\"bar\"}", "Expando is hidden from JSON.stringify" );
|
|
|
|
} );
|
2011-04-10 19:17:00 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( ".data should follow html5 specification regarding camel casing", function( assert ) {
|
|
|
|
assert.expect( 12 );
|
2011-04-10 19:17:00 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
var div = jQuery( "<div id='myObject' data-w-t-f='ftw' data-big-a-little-a='bouncing-b' data-foo='a' data-foo-bar='b' data-foo-bar-baz='c'></div>" )
|
|
|
|
.prependTo( "body" );
|
2011-04-10 19:17:00 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal( div.data()[ "wTF" ], "ftw", "Verify single letter data-* key" );
|
|
|
|
assert.equal( div.data()[ "bigALittleA" ], "bouncing-b", "Verify single letter mixed data-* key" );
|
2011-04-10 19:17:00 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal( div.data()[ "foo" ], "a", "Verify single word data-* key" );
|
|
|
|
assert.equal( div.data()[ "fooBar" ], "b", "Verify multiple word data-* key" );
|
|
|
|
assert.equal( div.data()[ "fooBarBaz" ], "c", "Verify multiple word data-* key" );
|
2011-09-07 14:13:22 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal( div.data( "foo" ), "a", "Verify single word data-* key" );
|
|
|
|
assert.equal( div.data( "fooBar" ), "b", "Verify multiple word data-* key" );
|
|
|
|
assert.equal( div.data( "fooBarBaz" ), "c", "Verify multiple word data-* key" );
|
2011-04-10 19:17:00 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
div.data( "foo-bar", "d" );
|
2011-05-10 15:56:42 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal( div.data( "fooBar" ), "d", "Verify updated data-* key" );
|
|
|
|
assert.equal( div.data( "foo-bar" ), "d", "Verify updated data-* key" );
|
2011-05-10 15:56:42 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal( div.data( "fooBar" ), "d", "Verify updated data-* key (fooBar)" );
|
|
|
|
assert.equal( div.data( "foo-bar" ), "d", "Verify updated data-* key (foo-bar)" );
|
2013-02-03 20:27:55 +00:00
|
|
|
|
2011-04-10 19:17:00 +00:00
|
|
|
div.remove();
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2011-06-07 00:18:36 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( ".data should not miss preset data-* w/ hyphenated property names", function( assert ) {
|
2011-06-07 00:18:36 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.expect( 2 );
|
2011-06-07 00:18:36 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
var div = jQuery( "<div/>", { id: "hyphened" } ).appendTo( "#qunit-fixture" ),
|
2011-06-07 00:18:36 +00:00
|
|
|
test = {
|
|
|
|
"camelBar": "camelBar",
|
|
|
|
"hyphen-foo": "hyphen-foo"
|
|
|
|
};
|
|
|
|
|
|
|
|
div.data( test );
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.each( test, function( i, k ) {
|
|
|
|
assert.equal( div.data( k ), k, "data with property '" + k + "' was correctly found" );
|
|
|
|
} );
|
|
|
|
} );
|
2011-07-11 01:42:40 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( "jQuery.data should not miss data-* w/ hyphenated property names #14047", function( assert ) {
|
2013-06-21 19:45:30 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.expect( 1 );
|
2013-06-21 19:45:30 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
var div = jQuery( "<div/>" );
|
2013-06-21 19:45:30 +00:00
|
|
|
|
|
|
|
div.data( "foo-bar", "baz" );
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal( jQuery.data( div[ 0 ], "foo-bar" ), "baz", "data with property 'foo-bar' was correctly found" );
|
|
|
|
} );
|
2013-06-21 19:45:30 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( ".data should not miss attr() set data-* with hyphenated property names", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2013-03-02 18:04:48 +00:00
|
|
|
|
2013-03-02 18:07:07 +00:00
|
|
|
var a, b;
|
2013-03-02 18:04:48 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
a = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
|
2013-03-02 18:04:48 +00:00
|
|
|
|
2013-03-02 18:07:07 +00:00
|
|
|
a.attr( "data-long-param", "test" );
|
2015-08-16 06:59:58 +00:00
|
|
|
a.data( "long-param", { a: 2 } );
|
2013-03-02 00:02:57 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.deepEqual( a.data( "long-param" ), { a: 2 }, "data with property long-param was found, 1" );
|
2013-03-02 00:02:57 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
b = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
|
2013-03-02 00:02:57 +00:00
|
|
|
|
2013-03-02 18:07:07 +00:00
|
|
|
b.attr( "data-long-param", "test" );
|
|
|
|
b.data( "long-param" );
|
2015-08-16 06:59:58 +00:00
|
|
|
b.data( "long-param", { a: 2 } );
|
2013-03-02 18:07:07 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.deepEqual( b.data( "long-param" ), { a: 2 }, "data with property long-param was found, 2" );
|
|
|
|
} );
|
2013-03-02 00:02:57 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( ".data always sets data with the camelCased key (gh-2257)", function( assert ) {
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 18 );
|
2015-05-04 13:36:58 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
var div = jQuery( "<div>" ).appendTo( "#qunit-fixture" ),
|
2015-05-04 13:36:58 +00:00
|
|
|
datas = {
|
|
|
|
"non-empty": "a string",
|
|
|
|
"empty-string": "",
|
|
|
|
"one-value": 1,
|
|
|
|
"zero-value": 0,
|
|
|
|
"an-array": [],
|
|
|
|
"an-object": {},
|
|
|
|
"bool-true": true,
|
|
|
|
"bool-false": false,
|
|
|
|
|
|
|
|
// JSHint enforces double quotes,
|
|
|
|
// but JSON strings need double quotes to parse
|
|
|
|
// so we need escaped double quotes here
|
|
|
|
"some-json": "{ \"foo\": \"bar\" }"
|
|
|
|
};
|
|
|
|
|
|
|
|
jQuery.each( datas, function( key, val ) {
|
|
|
|
div.data( key, val );
|
|
|
|
var allData = div.data();
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.equal( allData[ key ], undefined, ".data does not store with hyphenated keys" );
|
|
|
|
assert.equal( allData[ jQuery.camelCase( key ) ], val, ".data stores the camelCased key" );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
|
|
|
} );
|
2015-05-04 13:36:58 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( ".data should not strip more than one hyphen when camelCasing (gh-2070)", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2015-05-04 14:49:21 +00:00
|
|
|
var div = jQuery( "<div data-nested-single='single' data-nested--double='double' data-nested---triple='triple'></div>" ).appendTo( "#qunit-fixture" ),
|
|
|
|
allData = div.data();
|
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.equal( allData.nestedSingle, "single", "Key is correctly camelCased" );
|
|
|
|
assert.equal( allData[ "nested-Double" ], "double", "Key with double hyphens is correctly camelCased" );
|
|
|
|
assert.equal( allData[ "nested--Triple" ], "triple", "Key with triple hyphens is correctly camelCased" );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2015-05-04 14:49:21 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( ".data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function( assert ) {
|
2011-07-11 01:42:40 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
var div = jQuery( "<div/>", { id: "hyphened" } ).appendTo( "#qunit-fixture" ),
|
2011-07-11 01:42:40 +00:00
|
|
|
datas = {
|
|
|
|
"non-empty": "a string",
|
|
|
|
"empty-string": "",
|
|
|
|
"one-value": 1,
|
|
|
|
"zero-value": 0,
|
|
|
|
"an-array": [],
|
|
|
|
"an-object": {},
|
|
|
|
"bool-true": true,
|
|
|
|
"bool-false": false,
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2012-10-16 14:17:14 +00:00
|
|
|
// JSHint enforces double quotes,
|
|
|
|
// but JSON strings need double quotes to parse
|
|
|
|
// so we need escaped double quotes here
|
|
|
|
"some-json": "{ \"foo\": \"bar\" }",
|
2011-08-05 14:17:02 +00:00
|
|
|
"num-1-middle": true,
|
|
|
|
"num-end-2": true,
|
|
|
|
"2-num-start": true
|
2011-07-11 01:42:40 +00:00
|
|
|
};
|
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 24 );
|
2011-07-11 01:42:40 +00:00
|
|
|
|
|
|
|
jQuery.each( datas, function( key, val ) {
|
|
|
|
div.data( key, val );
|
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.deepEqual( div.data( key ), val, "get: " + key );
|
|
|
|
assert.deepEqual( div.data( jQuery.camelCase( key ) ), val, "get: " + jQuery.camelCase( key ) );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
|
|
|
} );
|
2011-07-11 01:42:40 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( ".data supports interoperable removal of hyphenated/camelCase properties", function( assert ) {
|
|
|
|
var div = jQuery( "<div/>", { id: "hyphened" } ).appendTo( "#qunit-fixture" ),
|
2011-08-05 13:43:15 +00:00
|
|
|
datas = {
|
|
|
|
"non-empty": "a string",
|
|
|
|
"empty-string": "",
|
|
|
|
"one-value": 1,
|
|
|
|
"zero-value": 0,
|
|
|
|
"an-array": [],
|
|
|
|
"an-object": {},
|
|
|
|
"bool-true": true,
|
|
|
|
"bool-false": false,
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2012-10-16 14:17:14 +00:00
|
|
|
// JSHint enforces double quotes,
|
|
|
|
// but JSON strings need double quotes to parse
|
|
|
|
// so we need escaped double quotes here
|
|
|
|
"some-json": "{ \"foo\": \"bar\" }"
|
2011-08-05 13:43:15 +00:00
|
|
|
};
|
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 27 );
|
2011-08-05 13:43:15 +00:00
|
|
|
|
|
|
|
jQuery.each( datas, function( key, val ) {
|
|
|
|
div.data( key, val );
|
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.deepEqual( div.data( key ), val, "get: " + key );
|
|
|
|
assert.deepEqual( div.data( jQuery.camelCase( key ) ), val, "get: " + jQuery.camelCase( key ) );
|
2011-08-05 13:43:15 +00:00
|
|
|
|
|
|
|
div.removeData( key );
|
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.equal( div.data( key ), undefined, "get: " + key );
|
2011-08-05 13:43:15 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
|
|
|
} );
|
2011-08-18 14:17:12 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( ".data supports interoperable removal of properties SET TWICE #13850", function( assert ) {
|
|
|
|
var div = jQuery( "<div>" ).appendTo( "#qunit-fixture" ),
|
2013-05-02 20:35:22 +00:00
|
|
|
datas = {
|
|
|
|
"non-empty": "a string",
|
|
|
|
"empty-string": "",
|
|
|
|
"one-value": 1,
|
|
|
|
"zero-value": 0,
|
|
|
|
"an-array": [],
|
|
|
|
"an-object": {},
|
|
|
|
"bool-true": true,
|
|
|
|
"bool-false": false,
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2013-05-02 20:35:22 +00:00
|
|
|
// JSHint enforces double quotes,
|
|
|
|
// but JSON strings need double quotes to parse
|
|
|
|
// so we need escaped double quotes here
|
|
|
|
"some-json": "{ \"foo\": \"bar\" }"
|
|
|
|
};
|
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 9 );
|
2013-05-02 20:35:22 +00:00
|
|
|
|
|
|
|
jQuery.each( datas, function( key, val ) {
|
|
|
|
div.data( key, val );
|
|
|
|
div.data( key, val );
|
|
|
|
|
|
|
|
div.removeData( key );
|
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.equal( div.data( key ), undefined, "removal: " + key );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
|
|
|
} );
|
2013-05-02 20:35:22 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( ".removeData supports removal of hyphenated properties via array (#12786, gh-2257)", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2012-10-24 18:12:28 +00:00
|
|
|
|
2012-10-25 14:50:57 +00:00
|
|
|
var div, plain, compare;
|
2012-10-24 18:12:28 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
div = jQuery( "<div>" ).appendTo( "#qunit-fixture" );
|
|
|
|
plain = jQuery( {} );
|
2012-10-24 18:12:28 +00:00
|
|
|
|
2015-05-04 13:36:58 +00:00
|
|
|
// Properties should always be camelCased
|
2012-10-25 14:50:57 +00:00
|
|
|
compare = {
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2012-10-25 14:50:57 +00:00
|
|
|
// From batch assignment .data({ "a-a": 1 })
|
2015-05-04 13:36:58 +00:00
|
|
|
"aA": 1,
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2012-10-25 14:50:57 +00:00
|
|
|
// From property, value assignment .data( "b-b", 1 )
|
|
|
|
"bB": 1
|
|
|
|
};
|
2012-10-24 18:12:28 +00:00
|
|
|
|
2012-10-25 14:50:57 +00:00
|
|
|
// Mixed assignment
|
2015-08-16 06:59:58 +00:00
|
|
|
div.data( { "a-a": 1 } ).data( "b-b", 1 );
|
|
|
|
plain.data( { "a-a": 1 } ).data( "b-b", 1 );
|
2012-10-24 18:12:28 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.deepEqual( div.data(), compare, "Data appears as expected. (div)" );
|
|
|
|
assert.deepEqual( plain.data(), compare, "Data appears as expected. (plain)" );
|
2012-10-24 18:12:28 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
div.removeData( [ "a-a", "b-b" ] );
|
|
|
|
plain.removeData( [ "a-a", "b-b" ] );
|
2012-10-25 14:50:57 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.deepEqual( div.data(), {}, "Data is empty. (div)" );
|
|
|
|
assert.deepEqual( plain.data(), {}, "Data is empty. (plain)" );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2012-10-24 18:12:28 +00:00
|
|
|
|
2011-08-18 14:17:12 +00:00
|
|
|
// Test originally by Moschel
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( ".removeData should not throw exceptions. (#10080)", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.stop();
|
2015-08-16 06:59:58 +00:00
|
|
|
var frame = jQuery( "#loadediframe" );
|
|
|
|
jQuery( frame[ 0 ].contentWindow ).on( "unload", function() {
|
|
|
|
assert.ok( true, "called unload" );
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.start();
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
|
|
|
|
2011-08-18 14:17:12 +00:00
|
|
|
// change the url to trigger unload
|
2015-08-16 06:59:58 +00:00
|
|
|
frame.attr( "src", "data/iframe.html?param=true" );
|
|
|
|
} );
|
2011-09-19 20:13:57 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( ".data only checks element attributes once. #8909", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2011-09-19 20:13:57 +00:00
|
|
|
var testing = {
|
2012-07-05 19:52:13 +00:00
|
|
|
"test": "testing",
|
|
|
|
"test2": "testing"
|
2011-09-19 20:13:57 +00:00
|
|
|
},
|
|
|
|
element = jQuery( "<div data-test='testing'>" ),
|
|
|
|
node = element[ 0 ];
|
|
|
|
|
|
|
|
// set an attribute using attr to ensure it
|
|
|
|
node.setAttribute( "data-test2", "testing" );
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.deepEqual( element.data(), testing, "Sanity Check" );
|
2011-09-19 20:13:57 +00:00
|
|
|
|
|
|
|
node.setAttribute( "data-test3", "testing" );
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.deepEqual( element.data(), testing, "The data didn't change even though the data-* attrs did" );
|
2011-09-19 20:13:57 +00:00
|
|
|
|
|
|
|
// clean up data cache
|
|
|
|
element.remove();
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2012-08-24 02:19:06 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "data-* with JSON value can have newlines", function( assert ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.expect( 1 );
|
2012-10-16 14:17:14 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
var x = jQuery( "<div data-some='{\n\"foo\":\n\t\"bar\"\n}'></div>" );
|
|
|
|
assert.equal( x.data( "some" ).foo, "bar", "got a JSON data- attribute with spaces" );
|
2012-08-24 02:19:06 +00:00
|
|
|
x.remove();
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2013-03-04 00:40:33 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( ".data doesn't throw when calling selection is empty. #13551", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2013-03-04 00:40:33 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
jQuery( null ).data( "prop" );
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.ok( true, "jQuery(null).data('prop') does not throw" );
|
2013-03-04 00:40:33 +00:00
|
|
|
} catch ( e ) {
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.ok( false, e.message );
|
2013-03-04 00:40:33 +00:00
|
|
|
}
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2013-04-08 19:10:39 +00:00
|
|
|
|
2015-08-25 02:56:57 +00:00
|
|
|
QUnit.test( "acceptData", function( assert ) {
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 10 );
|
2015-03-25 18:46:00 +00:00
|
|
|
|
2015-08-25 02:56:57 +00:00
|
|
|
var flash, pdf, form;
|
2013-09-18 13:41:07 +00:00
|
|
|
|
2015-08-25 02:56:57 +00:00
|
|
|
assert.equal( 42, jQuery( document ).data( "test", 42 ).data( "test" ), "document" );
|
|
|
|
assert.equal( 42, jQuery( document.documentElement ).data( "test", 42 ).data( "test" ), "documentElement" );
|
|
|
|
assert.equal( 42, jQuery( {} ).data( "test", 42 ).data( "test" ), "object" );
|
|
|
|
assert.equal( 42, jQuery( document.createElement( "embed" ) ).data( "test", 42 ).data( "test" ), "embed" );
|
2013-09-18 13:41:07 +00:00
|
|
|
|
|
|
|
flash = document.createElement( "object" );
|
|
|
|
flash.setAttribute( "classid", "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" );
|
2015-08-25 02:56:57 +00:00
|
|
|
assert.equal( 42, jQuery( flash ).data( "test", 42 ).data( "test" ), "flash" );
|
2013-04-08 19:10:39 +00:00
|
|
|
|
2015-01-25 00:32:54 +00:00
|
|
|
pdf = document.createElement( "object" );
|
|
|
|
pdf.setAttribute( "classid", "clsid:CA8A9780-280D-11CF-A24D-444553540000" );
|
2015-08-25 02:56:57 +00:00
|
|
|
assert.equal( 42, jQuery( pdf ).data( "test", 42 ).data( "test" ), "pdf" );
|
2013-09-18 13:41:07 +00:00
|
|
|
|
2015-08-25 02:56:57 +00:00
|
|
|
assert.equal( undefined, jQuery( document.createComment( "" ) ).data( "test", 42 ).data( "test" ), "comment" );
|
|
|
|
assert.equal( undefined, jQuery( document.createTextNode( "" ) ).data( "test", 42 ).data( "test" ), "text" );
|
|
|
|
assert.equal( undefined, jQuery( document.createDocumentFragment() ).data( "test", 42 ).data( "test" ), "documentFragment" );
|
2013-09-18 13:41:07 +00:00
|
|
|
|
2015-08-25 02:56:57 +00:00
|
|
|
form = jQuery( "#form" ).append( "<input id='nodeType'/><input id='nodeName'/>" )[ 0 ];
|
|
|
|
assert.equal( 42, jQuery( form ) .data( "test", 42 ).data( "test" ), "form with aliased DOM properties" );
|
2015-09-08 00:28:56 +00:00
|
|
|
} );
|
2013-04-08 19:10:39 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
QUnit.test( "Check proper data removal of non-element descendants nodes (#8335)", function( assert ) {
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 1 );
|
2015-07-29 15:10:04 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
var div = jQuery( "<div>text</div>" ),
|
2013-04-08 19:10:39 +00:00
|
|
|
text = div.contents();
|
|
|
|
|
|
|
|
text.data( "test", "test" ); // This should be a noop.
|
|
|
|
div.remove();
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.ok( !text.data( "test" ), "Be sure data is not stored in non-element" );
|
|
|
|
} );
|
2014-04-30 14:43:39 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
testIframeWithCallback(
|
|
|
|
"enumerate data attrs on body (#14894)",
|
|
|
|
"data/dataAttrs.html",
|
|
|
|
function( result, assert ) {
|
|
|
|
assert.expect( 1 );
|
|
|
|
assert.equal( result, "ok", "enumeration of data- attrs on body" );
|
|
|
|
}
|
|
|
|
);
|
2015-05-06 22:29:06 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "Check that the expando is removed when there's no more data", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2014-04-30 14:43:39 +00:00
|
|
|
|
2015-05-06 22:29:06 +00:00
|
|
|
var key,
|
|
|
|
div = jQuery( "<div/>" );
|
|
|
|
div.data( "some", "data" );
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.equal( div.data( "some" ), "data", "Data is added" );
|
2015-05-06 22:29:06 +00:00
|
|
|
div.removeData( "some" );
|
|
|
|
|
|
|
|
// Make sure the expando is gone
|
|
|
|
for ( key in div[ 0 ] ) {
|
|
|
|
if ( /^jQuery/.test( key ) ) {
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.ok( false, "Expando was not removed when there was no more data" );
|
2015-05-06 22:29:06 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2015-08-23 21:23:35 +00:00
|
|
|
|
|
|
|
QUnit.test( ".data(prop) does not create expando", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
|
|
|
|
|
|
|
var key,
|
|
|
|
div = jQuery( "<div/>" );
|
|
|
|
|
|
|
|
div.data("foo");
|
|
|
|
assert.equal( false, jQuery.hasData( div[0] ) );
|
|
|
|
// Make sure no expando has been added
|
|
|
|
for ( key in div[ 0 ] ) {
|
|
|
|
if ( /^jQuery/.test( key ) ) {
|
|
|
|
assert.ok( false, "Expando was created on access" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|