From d7a6e75241ecc433cd5228174960dd8465ca3ff7 Mon Sep 17 00:00:00 2001 From: jeresig Date: Wed, 22 Sep 2010 16:50:38 -0400 Subject: [PATCH] Add some tests for jQuery.isWindow and make sure that we're operating against an object before testing. --- src/core.js | 2 +- test/unit/core.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/core.js b/src/core.js index 9cb519be5..b747e5bea 100644 --- a/src/core.js +++ b/src/core.js @@ -476,7 +476,7 @@ jQuery.extend({ // A crude way of determining if an object is a window isWindow: function( obj ) { - return "setInterval" in obj; + return obj && typeof obj === "object" && "setInterval" in obj; }, type: function( obj ) { diff --git a/test/unit/core.js b/test/unit/core.js index 811d13fb4..eec3d7cdf 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -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() { expect(15); -- 2.39.5