Commit d7a6e752 authored by jeresig's avatar jeresig

Add some tests for jQuery.isWindow and make sure that we're operating against...

Add some tests for jQuery.isWindow and make sure that we're operating against an object before testing.
parent c8dd49f7
...@@ -476,7 +476,7 @@ jQuery.extend({ ...@@ -476,7 +476,7 @@ jQuery.extend({
// A crude way of determining if an object is a window // A crude way of determining if an object is a window
isWindow: function( obj ) { isWindow: function( obj ) {
return "setInterval" in obj; return obj && typeof obj === "object" && "setInterval" in obj;
}, },
type: function( obj ) { type: function( obj ) {
......
...@@ -432,6 +432,25 @@ test("isXMLDoc - XML", function() { ...@@ -432,6 +432,25 @@ test("isXMLDoc - XML", function() {
}); });
} }
test("isWindow", function() {
expect( 12 );
ok( jQuery.isWindow(window), "window" );
ok( !jQuery.isWindow(), "empty" );
ok( !jQuery.isWindow(null), "null" );
ok( !jQuery.isWindow(undefined), "undefined" );
ok( !jQuery.isWindow(document), "document" );
ok( !jQuery.isWindow(document.documentElement), "documentElement" );
ok( !jQuery.isWindow(""), "string" );
ok( !jQuery.isWindow(1), "number" );
ok( !jQuery.isWindow(true), "boolean" );
ok( !jQuery.isWindow({}), "object" );
// HMMM
// ok( !jQuery.isWindow({ setInterval: function(){} }), "fake window" );
ok( !jQuery.isWindow(/window/), "regexp" );
ok( !jQuery.isWindow(function(){}), "function" );
});
test("jQuery('html')", function() { test("jQuery('html')", function() {
expect(15); expect(15);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment