Bug Tracker

Ticket #2968: 2968.test.diff

File 2968.test.diff, 1.3 KB (added by genezys, 12 years ago)

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

  • test/unit/core.js

     
    107107});
    108108
    109109test("isFunction", function() {
    110         expect(21);
     110        expect(27);
    111111
    112112        // Make sure that false values return false
    113113        ok( !jQuery.isFunction(), "No Value" );
     
    138138        // Make sure normal functions still work
    139139        var fn = function(){};
    140140        ok( jQuery.isFunction(fn), "Normal Function" );
     141       
     142        // Edge cases (bug #2968 #3134)
     143        var fnWithToString = function(){};
     144        fnWithToString.toString = function(){ return "Test"; };
     145        fnWithToString.valueOf = function(){ return "Test"; };
     146        ok( jQuery.isFunction(fnWithToString), "Normal Function with toString() and valueOf() overridden" );
     147        ok( !jQuery.isFunction(new String("function")), 'new String("function")' );
     148        ok( !jQuery.isFunction({toString:function(){return "function"}}), 'Object with toString()' );
     149        ok( !jQuery.isFunction({valueOf:function(){return "function"}}), "Object with valueOf()" );
    141150
     151        // Native functions in IE
     152        ok( jQuery.isFunction( window.alert ), "alert()" );
     153        ok( jQuery.isFunction( window.prompt ), "prompt()" );   
     154
    142155        var obj = document.createElement("object");
    143156
    144157        // Firefox says this is a function