Skip to content

Commit 25b85d9

Browse files
committed
Core: Warn against jQuery.now & jQuery.camelCase
These APIs have been deprecated in jQuery 3.3. Fixes gh-594 Fixes gh-595
1 parent 8b1fb5c commit 25b85d9

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

src/jquery/core.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ if ( jQueryVersionSince( "3.3.0" ) ) {
114114
"jQuery.isWindow() is deprecated"
115115
);
116116

117+
migratePatchAndWarnFunc( jQuery, "now", Date.now, "now",
118+
"jQuery.now() is deprecated; use Date.now()"
119+
);
120+
121+
migratePatchAndWarnFunc( jQuery, "camelCase", jQuery.camelCase, "camelCase",
122+
"jQuery.camelCase() is deprecated"
123+
);
124+
117125
// Bind a function to a context, optionally partially applying any
118126
// arguments.
119127
// jQuery.proxy is deprecated to promote standards (specifically Function#bind)

test/unit/jquery/core.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,35 @@ QUnit[ jQueryVersionSince( "3.3.0" ) ? "test" : "skip" ]( "jQuery.isWindow", fun
199199
} );
200200
} );
201201

202+
QUnit[ jQueryVersionSince( "3.3.0" ) ? "test" : "skip" ]( "jQuery.now", function( assert ) {
203+
assert.expect( 2 );
204+
205+
expectWarning( assert, "now", 1, function() {
206+
assert.ok( typeof jQuery.now() === "number", "jQuery.now is a function" );
207+
} );
208+
} );
209+
210+
QUnit[ jQueryVersionSince( "3.3.0" ) ? "test" : "skip" ]( "jQuery.camelCase()", function( assert ) {
211+
212+
var tests = {
213+
"foo-bar": "fooBar",
214+
"foo-bar-baz": "fooBarBaz",
215+
"girl-u-want": "girlUWant",
216+
"the-4th-dimension": "the-4thDimension",
217+
"-o-tannenbaum": "OTannenbaum",
218+
"-moz-illa": "MozIlla",
219+
"-ms-take": "msTake"
220+
};
221+
222+
assert.expect( 8 );
223+
224+
expectWarning( assert, "now", 7, function() {
225+
jQuery.each( tests, function( key, val ) {
226+
assert.equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val );
227+
} );
228+
} );
229+
} );
230+
202231
QUnit.test( "jQuery.unique", function( assert ) {
203232
assert.expect( 2 );
204233

warnings.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ This is _not_ a warning, but a console log message the plugin shows when it firs
9999

100100
**Solution**: Replace any use of `.size()` with `.length`.
101101

102+
### \[now\] JQMIGRATE: jQuery.now() is deprecated; use Date.now
103+
104+
**Cause:** The `jQuery.now()` method was a simple alias for `Date.now()`, which is now supported in all browsers supported by jQuery 3.0.
105+
106+
**Solution:** Replace any calls to `jQuery.now()` with `Date.now()`.
107+
108+
### \[camelCase\] JQMIGRATE: jQuery.camelCase() is deprecated
109+
110+
**Cause:** The `jQuery.camelCase()` method was a utility to convert dashed strings like `"background-color"` into camel-cased strings like `"backgroundColor"`. This method was never documented and is now deprecated.
111+
112+
**Solution:** If you need this functionality, you can implement it yourself.
113+
102114
### \[data-camelCase\] JQMIGRATE: jQuery.data() always sets/gets camelCased names
103115

104116
**Cause:** The page is attempting to set or get a jQuery data item using kebab case, e.g. `my-data`, when a `my-data` item has been set directly on the jQuery data object. jQuery 3.0 always exclusively uses camel case, e.g., `myData`, when it accesses data items via the `.data()` API and does not find kebab case data in that object.

0 commit comments

Comments
 (0)