]> source.dussan.org Git - jquery.git/commitdiff
Core: adjust data tests to ensure proper camelCasing
authorTimmy Willison <4timmywil@gmail.com>
Mon, 4 Dec 2017 21:38:37 +0000 (16:38 -0500)
committerTimmy Willison <4timmywil@gmail.com>
Mon, 8 Jan 2018 16:21:22 +0000 (11:21 -0500)
- Add back camelCase to the public object (deprecate not remove)
Ref #3384

src/deprecated.js
test/unit/data.js

index 3ae78aac8d4db9af4f10a4478d9c30f0a1027f80..08c95538fe6f3d1901b3432cc80b4f708b76dc6e 100644 (file)
@@ -1,8 +1,9 @@
 define( [
        "./core",
        "./core/nodeName",
+       "./core/camelCase",
        "./var/isWindow"
-], function( jQuery, nodeName, isWindow ) {
+], function( jQuery, nodeName, camelCase, isWindow ) {
 
 "use strict";
 
@@ -38,5 +39,6 @@ jQuery.isArray = Array.isArray;
 jQuery.parseJSON = JSON.parse;
 jQuery.nodeName = nodeName;
 jQuery.isWindow = isWindow;
+jQuery.camelCase = camelCase;
 
 } );
index 5824c2f9d6e10e5153a597f0fd86ad85c5918e97..c769d9040f37260ea86e8a88a337c9931dcd3c6c 100644 (file)
@@ -602,29 +602,57 @@ QUnit.test( ".data should not miss attr() set data-* with hyphenated property na
 } );
 
 QUnit.test( ".data always sets data with the camelCased key (gh-2257)", function( assert ) {
-       assert.expect( 9 );
+       assert.expect( 18 );
 
        var div = jQuery( "<div>" ).appendTo( "#qunit-fixture" ),
                datas = {
-                       "non-empty": "a string",
-                       "empty-string": "",
-                       "one-value": 1,
-                       "zero-value": 0,
-                       "an-array": [],
-                       "an-object": {},
-                       "bool-true": true,
-                       "bool-false": false,
+                       "non-empty": {
+                               key: "nonEmpty",
+                               value: "a string"
+                       },
+                       "empty-string": {
+                               key: "emptyString",
+                               value: ""
+                       },
+                       "one-value": {
+                               key: "oneValue",
+                               value: 1
+                       },
+                       "zero-value": {
+                               key: "zeroValue",
+                               value: 0
+                       },
+                       "an-array": {
+                               key: "anArray",
+                               value: []
+                       },
+                       "an-object": {
+                               key: "anObject",
+                               value: {}
+                       },
+                       "bool-true": {
+                               key: "boolTrue",
+                               value: true
+                       },
+                       "bool-false": {
+                               key: "boolFalse",
+                               value: false
+                       },
 
                        // JSHint enforces double quotes,
                        // but JSON strings need double quotes to parse
                        // so we need escaped double quotes here
-                       "some-json": "{ \"foo\": \"bar\" }"
+                       "some-json": {
+                               key: "someJson",
+                               value: "{ \"foo\": \"bar\" }"
+                       }
                };
 
        jQuery.each( datas, function( key, val ) {
-               div.data( key, val );
+               div.data( key, val.value );
                var allData = div.data();
                assert.equal( allData[ key ], undefined, ".data does not store with hyphenated keys" );
+               assert.equal( allData[ val.key ], val.value, ".data stores the camelCased key" );
        } );
 } );
 
@@ -638,38 +666,76 @@ QUnit.test( ".data should not strip more than one hyphen when camelCasing (gh-20
        assert.equal( allData[ "nested--Triple" ], "triple", "Key with triple hyphens is correctly camelCased" );
 } );
 
-QUnit.test( ".data supports interoperable hyphenated get/set of properties with arbitrary non-null|NaN|undefined values", function( assert ) {
+QUnit.test( ".data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function( assert ) {
 
        var div = jQuery( "<div/>", { id: "hyphened" } ).appendTo( "#qunit-fixture" ),
                datas = {
-                       "non-empty": "a string",
-                       "empty-string": "",
-                       "one-value": 1,
-                       "zero-value": 0,
-                       "an-array": [],
-                       "an-object": {},
-                       "bool-true": true,
-                       "bool-false": false,
+                       "non-empty": {
+                               key: "nonEmpty",
+                               value: "a string"
+                       },
+                       "empty-string": {
+                               key: "emptyString",
+                               value: ""
+                       },
+                       "one-value": {
+                               key: "oneValue",
+                               value: 1
+                       },
+                       "zero-value": {
+                               key: "zeroValue",
+                               value: 0
+                       },
+                       "an-array": {
+                               key: "anArray",
+                               value: []
+                       },
+                       "an-object": {
+                               key: "anObject",
+                               value: {}
+                       },
+                       "bool-true": {
+                               key: "boolTrue",
+                               value: true
+                       },
+                       "bool-false": {
+                               key: "boolFalse",
+                               value: false
+                       },
 
                        // JSHint enforces double quotes,
                        // but JSON strings need double quotes to parse
                        // so we need escaped double quotes here
-                       "some-json": "{ \"foo\": \"bar\" }",
-                       "num-1-middle": true,
-                       "num-end-2": true,
-                       "2-num-start": true
+                       "some-json": {
+                               key: "someJson",
+                               value: "{ \"foo\": \"bar\" }"
+                       },
+
+                       "num-1-middle": {
+                               key: "num-1Middle",
+                               value: true
+                       },
+                       "num-end-2": {
+                               key: "numEnd-2",
+                               value: true
+                       },
+                       "2-num-start": {
+                               key: "2NumStart",
+                               value: true
+                       }
                };
 
-       assert.expect( 12 );
+       assert.expect( 24 );
 
        jQuery.each( datas, function( key, val ) {
-               div.data( key, val );
+               div.data( key, val.value );
 
-               assert.deepEqual( div.data( key ), val, "get: " + key );
+               assert.deepEqual( div.data( key ), val.value, "get: " + key );
+               assert.deepEqual( div.data( val.key ), val.value, "get: " + val.key );
        } );
 } );
 
-QUnit.test( ".data supports interoperable removal of hyphenated properties", function( assert ) {
+QUnit.test( ".data supports interoperable removal of hyphenated/camelCase properties", function( assert ) {
        var div = jQuery( "<div/>", { id: "hyphened" } ).appendTo( "#qunit-fixture" ),
                datas = {
                        "non-empty": "a string",
@@ -687,12 +753,13 @@ QUnit.test( ".data supports interoperable removal of hyphenated properties", fun
                        "some-json": "{ \"foo\": \"bar\" }"
                };
 
-       assert.expect( 18 );
+       assert.expect( 27 );
 
        jQuery.each( datas, function( key, val ) {
                div.data( key, val );
 
                assert.deepEqual( div.data( key ), val, "get: " + key );
+               assert.deepEqual( div.data( jQuery.camelCase( key ) ), val, "get: " + jQuery.camelCase( key ) );
 
                div.removeData( key );