Skip to content
Permalink
Browse files

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

… against an object before testing.
  • Loading branch information
jeresig committed Sep 22, 2010
1 parent c8dd49f commit d7a6e75241ecc433cd5228174960dd8465ca3ff7
Showing with 20 additions and 1 deletion.
  1. +1 −1 src/core.js
  2. +19 −0 test/unit/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;

This comment has been minimized.

Copy link
@lsmith

lsmith Sep 23, 2010

The obj test seems unnecessary.
return typeof obj === "object" && "setInterval" in obj;

This comment has been minimized.

Copy link
@jeresig

jeresig Sep 23, 2010

Author Member

I ran into problems with "setInterval" in obj when obj was null, in that case.

This comment has been minimized.

Copy link
@lsmith

lsmith Sep 23, 2010

Duh. Of course.

},

type: function( obj ) {
@@ -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);

0 comments on commit d7a6e75

Please sign in to comment.
You can’t perform that action at this time.