diff options
author | Jason Bedard <jason+github@jbedard.ca> | 2017-12-12 22:43:30 -0800 |
---|---|---|
committer | Jason Bedard <jason+github@jbedard.ca> | 2018-01-15 09:26:19 -0800 |
commit | 3d732cca6b5076a9d13eee98e2b075b37384cd91 (patch) | |
tree | 7ad2375d276c212e7d252554b3f87e5b0b3bec5e /test | |
parent | 6c38ebbd47c6b0fa654733819bd5ae36c1ac6c48 (diff) | |
download | jquery-3d732cca6b5076a9d13eee98e2b075b37384cd91.tar.gz jquery-3d732cca6b5076a9d13eee98e2b075b37384cd91.zip |
Core: deprecate jQuery.isFunction
Fixes gh-3609
Diffstat (limited to 'test')
-rw-r--r-- | test/data/testinit.js | 4 | ||||
-rw-r--r-- | test/unit/basic.js | 5 | ||||
-rw-r--r-- | test/unit/core.js | 147 | ||||
-rw-r--r-- | test/unit/deferred.js | 6 | ||||
-rw-r--r-- | test/unit/deprecated.js | 155 | ||||
-rw-r--r-- | test/unit/effects.js | 2 | ||||
-rw-r--r-- | test/unit/manipulation.js | 2 | ||||
-rw-r--r-- | test/unit/queue.js | 2 |
8 files changed, 164 insertions, 159 deletions
diff --git a/test/data/testinit.js b/test/data/testinit.js index d6c0236e6..211824a89 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -171,7 +171,7 @@ this.ajaxTest = function( title, expect, options ) { QUnit.test( title, expect, function( assert ) { var requestOptions; - if ( jQuery.isFunction( options ) ) { + if ( typeof options === "function" ) { options = options( assert ); } options = options || []; @@ -208,7 +208,7 @@ this.ajaxTest = function( title, expect, options ) { if ( !completed ) { if ( !handler ) { assert.ok( false, "unexpected " + status ); - } else if ( jQuery.isFunction( handler ) ) { + } else if ( typeof handler === "function" ) { handler.apply( this, arguments ); } } diff --git a/test/unit/basic.js b/test/unit/basic.js index b46a04c28..29042caa5 100644 --- a/test/unit/basic.js +++ b/test/unit/basic.js @@ -76,7 +76,7 @@ QUnit.test( "show/hide", function( assert ) { } QUnit.test( "core", function( assert ) { - assert.expect( 25 ); + assert.expect( 23 ); var elem = jQuery( "<div></div><span></span>" ); @@ -90,9 +90,6 @@ QUnit.test( "core", function( assert ) { assert.ok( jQuery.isPlainObject( { "a": 2 } ), "jQuery.isPlainObject(object)" ); assert.ok( !jQuery.isPlainObject( "foo" ), "jQuery.isPlainObject(String)" ); - assert.ok( jQuery.isFunction( jQuery.noop ), "jQuery.isFunction(jQuery.noop)" ); - assert.ok( !jQuery.isFunction( 2 ), "jQuery.isFunction(Number)" ); - assert.ok( jQuery.isNumeric( "-2" ), "jQuery.isNumeric(String representing a number)" ); assert.ok( !jQuery.isNumeric( "" ), "jQuery.isNumeric(\"\")" ); diff --git a/test/unit/core.js b/test/unit/core.js index 7c7514ccc..fcff895b1 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -404,153 +404,6 @@ QUnit[ "assign" in Object ? "test" : "skip" ]( "isPlainObject(Object.assign(...) } ); - -QUnit.test( "isFunction", function( assert ) { - assert.expect( 20 ); - - var mystr, myarr, myfunction, fn, obj, nodes, first, input, a; - - // Make sure that false values return false - assert.ok( !jQuery.isFunction(), "No Value" ); - assert.ok( !jQuery.isFunction( null ), "null Value" ); - assert.ok( !jQuery.isFunction( undefined ), "undefined Value" ); - assert.ok( !jQuery.isFunction( "" ), "Empty String Value" ); - assert.ok( !jQuery.isFunction( 0 ), "0 Value" ); - - // Check built-ins - assert.ok( jQuery.isFunction( String ), "String Function(" + String + ")" ); - assert.ok( jQuery.isFunction( Array ), "Array Function(" + Array + ")" ); - assert.ok( jQuery.isFunction( Object ), "Object Function(" + Object + ")" ); - assert.ok( jQuery.isFunction( Function ), "Function Function(" + Function + ")" ); - - // When stringified, this could be misinterpreted - mystr = "function"; - assert.ok( !jQuery.isFunction( mystr ), "Function String" ); - - // When stringified, this could be misinterpreted - myarr = [ "function" ]; - assert.ok( !jQuery.isFunction( myarr ), "Function Array" ); - - // When stringified, this could be misinterpreted - myfunction = { "function": "test" }; - assert.ok( !jQuery.isFunction( myfunction ), "Function Object" ); - - // Make sure normal functions still work - fn = function() {}; - assert.ok( jQuery.isFunction( fn ), "Normal Function" ); - - assert.notOk( jQuery.isFunction( Object.create( fn ) ), "custom Function subclass" ); - - obj = document.createElement( "object" ); - - // Some versions of Firefox and Chrome say this is a function - assert.ok( !jQuery.isFunction( obj ), "Object Element" ); - - // Since 1.3, this isn't supported (#2968) - //ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" ); - - nodes = document.body.childNodes; - - // Safari says this is a function - assert.ok( !jQuery.isFunction( nodes ), "childNodes Property" ); - - first = document.body.firstChild; - - // Normal elements are reported ok everywhere - assert.ok( !jQuery.isFunction( first ), "A normal DOM Element" ); - - input = document.createElement( "input" ); - input.type = "text"; - document.body.appendChild( input ); - - // Since 1.3, this isn't supported (#2968) - //ok( jQuery.isFunction(input.focus), "A default function property" ); - - document.body.removeChild( input ); - - a = document.createElement( "a" ); - a.href = "some-function"; - document.body.appendChild( a ); - - // This serializes with the word 'function' in it - assert.ok( !jQuery.isFunction( a ), "Anchor Element" ); - - document.body.removeChild( a ); - - // Recursive function calls have lengths and array-like properties - function callme( callback ) { - function fn( response ) { - callback( response ); - } - - assert.ok( jQuery.isFunction( fn ), "Recursive Function Call" ); - - fn( { some: "data" } ); - } - - callme( function() { - callme( function() {} ); - } ); -} ); - -QUnit.test( "isFunction(cross-realm function)", function( assert ) { - assert.expect( 1 ); - - var iframe, doc, - done = assert.async(); - - // Functions from other windows should be matched - Globals.register( "iframeDone" ); - window.iframeDone = function( fn, detail ) { - window.iframeDone = undefined; - assert.ok( jQuery.isFunction( fn ), "cross-realm function" + - ( detail ? " - " + detail : "" ) ); - done(); - }; - - iframe = jQuery( "#qunit-fixture" )[ 0 ].appendChild( document.createElement( "iframe" ) ); - doc = iframe.contentDocument || iframe.contentWindow.document; - doc.open(); - doc.write( "<body onload='window.parent.iframeDone( function() {} );'>" ); - doc.close(); -} ); - -supportjQuery.each( - { - GeneratorFunction: "function*() {}", - AsyncFunction: "async function() {}" - }, - function( subclass, source ) { - var fn; - try { - fn = Function( "return " + source )(); - } catch ( e ) {} - - QUnit[ fn ? "test" : "skip" ]( "isFunction(" + subclass + ")", - function( assert ) { - assert.expect( 1 ); - - assert.equal( jQuery.isFunction( fn ), true, source ); - } - ); - } -); - -QUnit[ typeof Symbol === "function" && Symbol.toStringTag ? "test" : "skip" ]( - "isFunction(custom @@toStringTag)", - function( assert ) { - assert.expect( 2 ); - - var obj = {}, - fn = function() {}; - obj[ Symbol.toStringTag ] = "Function"; - fn[ Symbol.toStringTag ] = "Object"; - - assert.equal( jQuery.isFunction( obj ), false, "function-mimicking object" ); - assert.equal( jQuery.isFunction( fn ), true, "object-mimicking function" ); - } -); - QUnit.test( "isNumeric", function( assert ) { assert.expect( 43 ); diff --git a/test/unit/deferred.js b/test/unit/deferred.js index f64d4fec8..9ba97181d 100644 --- a/test/unit/deferred.js +++ b/test/unit/deferred.js @@ -14,7 +14,7 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) { var defer = createDeferred(); - assert.ok( jQuery.isFunction( defer.pipe ), "defer.pipe is a function" ); + assert.ok( typeof defer.pipe === "function", "defer.pipe is a function" ); defer.resolve().done( function() { assert.ok( true, "Success on resolve" ); @@ -49,7 +49,7 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) { assert.strictEqual( defer.promise(), promise, "promise is always the same" ); assert.strictEqual( funcPromise, func, "non objects get extended" ); jQuery.each( promise, function( key ) { - if ( !jQuery.isFunction( promise[ key ] ) ) { + if ( typeof promise[ key ] !== "function" ) { assert.ok( false, key + " is a function (" + jQuery.type( promise[ key ] ) + ")" ); } if ( promise[ key ] !== func[ key ] ) { @@ -1097,7 +1097,7 @@ QUnit.test( "jQuery.when - always returns a new promise", function( assert ) { }, function( label, args ) { var result = jQuery.when.apply( jQuery, args ); - assert.ok( jQuery.isFunction( result.then ), "Thenable returned from " + label ); + assert.ok( typeof result.then === "function", "Thenable returned from " + label ); assert.strictEqual( result.resolve, undefined, "Non-deferred returned from " + label ); assert.strictEqual( result.promise(), result, "Promise returned from " + label ); diff --git a/test/unit/deprecated.js b/test/unit/deprecated.js index 9837b3bae..19810151f 100644 --- a/test/unit/deprecated.js +++ b/test/unit/deprecated.js @@ -165,6 +165,161 @@ QUnit.test( "jQuery.nodeName", function( assert ) { ); } ); + +QUnit.test( "core", function( assert ) { + assert.expect( 2 ); + + assert.ok( jQuery.isFunction( jQuery.noop ), "jQuery.isFunction(jQuery.noop)" ); + assert.ok( !jQuery.isFunction( 2 ), "jQuery.isFunction(Number)" ); +} ); + + +QUnit.test( "isFunction", function( assert ) { + assert.expect( 20 ); + + var mystr, myarr, myfunction, fn, obj, nodes, first, input, a; + + // Make sure that false values return false + assert.ok( !jQuery.isFunction(), "No Value" ); + assert.ok( !jQuery.isFunction( null ), "null Value" ); + assert.ok( !jQuery.isFunction( undefined ), "undefined Value" ); + assert.ok( !jQuery.isFunction( "" ), "Empty String Value" ); + assert.ok( !jQuery.isFunction( 0 ), "0 Value" ); + + // Check built-ins + assert.ok( jQuery.isFunction( String ), "String Function(" + String + ")" ); + assert.ok( jQuery.isFunction( Array ), "Array Function(" + Array + ")" ); + assert.ok( jQuery.isFunction( Object ), "Object Function(" + Object + ")" ); + assert.ok( jQuery.isFunction( Function ), "Function Function(" + Function + ")" ); + + // When stringified, this could be misinterpreted + mystr = "function"; + assert.ok( !jQuery.isFunction( mystr ), "Function String" ); + + // When stringified, this could be misinterpreted + myarr = [ "function" ]; + assert.ok( !jQuery.isFunction( myarr ), "Function Array" ); + + // When stringified, this could be misinterpreted + myfunction = { "function": "test" }; + assert.ok( !jQuery.isFunction( myfunction ), "Function Object" ); + + // Make sure normal functions still work + fn = function() {}; + assert.ok( jQuery.isFunction( fn ), "Normal Function" ); + + assert.notOk( jQuery.isFunction( Object.create( fn ) ), "custom Function subclass" ); + + obj = document.createElement( "object" ); + + // Some versions of Firefox and Chrome say this is a function + assert.ok( !jQuery.isFunction( obj ), "Object Element" ); + + // Since 1.3, this isn't supported (#2968) + //ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" ); + + nodes = document.body.childNodes; + + // Safari says this is a function + assert.ok( !jQuery.isFunction( nodes ), "childNodes Property" ); + + first = document.body.firstChild; + + // Normal elements are reported ok everywhere + assert.ok( !jQuery.isFunction( first ), "A normal DOM Element" ); + + input = document.createElement( "input" ); + input.type = "text"; + document.body.appendChild( input ); + + // Since 1.3, this isn't supported (#2968) + //ok( jQuery.isFunction(input.focus), "A default function property" ); + + document.body.removeChild( input ); + + a = document.createElement( "a" ); + a.href = "some-function"; + document.body.appendChild( a ); + + // This serializes with the word 'function' in it + assert.ok( !jQuery.isFunction( a ), "Anchor Element" ); + + document.body.removeChild( a ); + + // Recursive function calls have lengths and array-like properties + function callme( callback ) { + function fn( response ) { + callback( response ); + } + + assert.ok( jQuery.isFunction( fn ), "Recursive Function Call" ); + + fn( { some: "data" } ); + } + + callme( function() { + callme( function() {} ); + } ); +} ); + +QUnit.test( "isFunction(cross-realm function)", function( assert ) { + assert.expect( 1 ); + + var iframe, doc, + done = assert.async(); + + // Functions from other windows should be matched + Globals.register( "iframeDone" ); + window.iframeDone = function( fn, detail ) { + window.iframeDone = undefined; + assert.ok( jQuery.isFunction( fn ), "cross-realm function" + + ( detail ? " - " + detail : "" ) ); + done(); + }; + + iframe = jQuery( "#qunit-fixture" )[ 0 ].appendChild( document.createElement( "iframe" ) ); + doc = iframe.contentDocument || iframe.contentWindow.document; + doc.open(); + doc.write( "<body onload='window.parent.iframeDone( function() {} );'>" ); + doc.close(); +} ); + +supportjQuery.each( + { + GeneratorFunction: "function*() {}", + AsyncFunction: "async function() {}" + }, + function( subclass, source ) { + var fn; + try { + fn = Function( "return " + source )(); + } catch ( e ) {} + + QUnit[ fn ? "test" : "skip" ]( "isFunction(" + subclass + ")", + function( assert ) { + assert.expect( 1 ); + + assert.equal( jQuery.isFunction( fn ), true, source ); + } + ); + } +); + +QUnit[ typeof Symbol === "function" && Symbol.toStringTag ? "test" : "skip" ]( + "isFunction(custom @@toStringTag)", + function( assert ) { + assert.expect( 2 ); + + var obj = {}, + fn = function() {}; + obj[ Symbol.toStringTag ] = "Function"; + fn[ Symbol.toStringTag ] = "Object"; + + assert.equal( jQuery.isFunction( obj ), false, "function-mimicking object" ); + assert.equal( jQuery.isFunction( fn ), true, "object-mimicking function" ); + } +); + QUnit.test( "jQuery.isWindow", function( assert ) { assert.expect( 14 ); diff --git a/test/unit/effects.js b/test/unit/effects.js index d023dc8c1..462524ef3 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -2507,7 +2507,7 @@ function testEasing( assert, speed, easing, complete ) { assert.equal( options.duration, 10, "Duration set properly" ); assert.equal( - jQuery.isFunction( options.easing ) ? options.easing() : options.easing, + typeof options.easing === "function" ? options.easing() : options.easing, "linear", "Easing set properly" ); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 528a192ce..07ab43419 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -1415,7 +1415,7 @@ QUnit.test( "jQuery.clone() (#8017)", function( assert ) { assert.expect( 2 ); - assert.ok( jQuery.clone && jQuery.isFunction( jQuery.clone ), "jQuery.clone() utility exists and is a function." ); + assert.ok( jQuery.clone && typeof jQuery.clone === "function", "jQuery.clone() utility exists and is a function." ); var main = jQuery( "#qunit-fixture" )[ 0 ], clone = jQuery.clone( main ); diff --git a/test/unit/queue.js b/test/unit/queue.js index 0a6862d6b..f604cea04 100644 --- a/test/unit/queue.js +++ b/test/unit/queue.js @@ -261,7 +261,7 @@ QUnit.test( ".promise(obj)", function( assert ) { var obj = {}, promise = jQuery( "#foo" ).promise( "promise", obj ); - assert.ok( jQuery.isFunction( promise.promise ), ".promise(type, obj) returns a promise" ); + assert.ok( typeof promise.promise === "function", ".promise(type, obj) returns a promise" ); assert.strictEqual( promise, obj, ".promise(type, obj) returns obj" ); } ); |