Skip to main content

Bug Tracker

Side navigation

Ticket #2968: 2968.test.diff
File 2968.test.diff, 1.3 KB (added by genezys, July 07, 2008 08:42PM UTC)

Added test cases for isFunction (merging these one and bug #3134)

Index: test/unit/core.js
===================================================================
--- test/unit/core.js	(revision 5772)
+++ test/unit/core.js	(working copy)
@@ -107,7 +107,7 @@
 });
 
 test("isFunction", function() {
-	expect(21);
+	expect(27);
 
 	// Make sure that false values return false
 	ok( !jQuery.isFunction(), "No Value" );
@@ -138,7 +138,20 @@
 	// Make sure normal functions still work
 	var fn = function(){};
 	ok( jQuery.isFunction(fn), "Normal Function" );
+	
+	// Edge cases (bug #2968 #3134)
+	var fnWithToString = function(){};
+	fnWithToString.toString = function(){ return "Test"; };
+	fnWithToString.valueOf = function(){ return "Test"; };
+	ok( jQuery.isFunction(fnWithToString), "Normal Function with toString() and valueOf() overridden" );
+	ok( !jQuery.isFunction(new String("function")), 'new String("function")' );
+	ok( !jQuery.isFunction({toString:function(){return "function"}}), 'Object with toString()' );
+	ok( !jQuery.isFunction({valueOf:function(){return "function"}}), "Object with valueOf()" );
 
+	// Native functions in IE
+	ok( jQuery.isFunction( window.alert ), "alert()" );
+	ok( jQuery.isFunction( window.prompt ), "prompt()" );	
+
 	var obj = document.createElement("object");
 
 	// Firefox says this is a function

Download in other formats:

Original Format