diff options
-rw-r--r-- | src/core.js | 3 | ||||
-rw-r--r-- | test/unit/core.js | 10 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/core.js b/src/core.js index 0b99b74a2..85a381661 100644 --- a/src/core.js +++ b/src/core.js @@ -679,6 +679,9 @@ jQuery.extend({ }, inArray: function( elem, array ) { + if ( !array ) { + return -1; + } if ( indexOf ) { return indexOf.call( array, elem ); diff --git a/test/unit/core.js b/test/unit/core.js index 40ee80f6a..a6783e02e 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -934,6 +934,16 @@ test("jQuery.makeArray", function(){ same( jQuery.makeArray({length: "5"}), [], "Make sure object is coerced properly."); }); +test("jQuery.inArray", function(){ + expect(3); + + equals( jQuery.inArray( 0, false ), -1 , "Search in 'false' as array returns -1 and doesn't throw exception" ); + + equals( jQuery.inArray( 0, null ), -1 , "Search in 'null' as array returns -1 and doesn't throw exception" ); + + equals( jQuery.inArray( 0, undefined ), -1 , "Search in 'undefined' as array returns -1 and doesn't throw exception" ); +}); + test("jQuery.isEmptyObject", function(){ expect(2); |