From 6ca766d5eae5e6ae2d3f9e8222dbd042e7e92dca Mon Sep 17 00:00:00 2001 From: Josh Susser Date: Wed, 24 Feb 2010 19:35:32 -0800 Subject: [PATCH] Update isArray_ function and add test coverage --- lib/jasmine-0.10.0.js | 8 ++------ spec/suites/UtilSpec.js | 17 +++++++++++++++++ src/base.js | 6 +----- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/jasmine-0.10.0.js b/lib/jasmine-0.10.0.js index 165446d..99178a9 100644 --- a/lib/jasmine-0.10.0.js +++ b/lib/jasmine-0.10.0.js @@ -89,11 +89,7 @@ jasmine.getEnv = function() { * @returns {Boolean} */ jasmine.isArray_ = function(value) { - return value && - typeof value === 'object' && - typeof value.length === 'number' && - typeof value.splice === 'function' && - !(value.propertyIsEnumerable('length')); + return Object.prototype.toString.apply(value) === '[object Array]'; }; /** @@ -2261,5 +2257,5 @@ jasmine.version_= { "major": 0, "minor": 10, "build": 0, - "revision": 1267068340 + "revision": 1267068885 }; diff --git a/spec/suites/UtilSpec.js b/spec/suites/UtilSpec.js index 6731034..93f503a 100644 --- a/spec/suites/UtilSpec.js +++ b/spec/suites/UtilSpec.js @@ -20,4 +20,21 @@ describe("jasmine.util", function() { expect(destination).toEqual({foo: null}); }); }); + + describe("isArray_", function() { + it("should return true if the argument is an array", function() { + expect(jasmine.isArray_([])).toBe(true); + expect(jasmine.isArray_(['a'])).toBe(true); + expect(jasmine.isArray_(new Array())).toBe(true); + }); + + it("should return false if the argument is not an array", function() { + expect(jasmine.isArray_(undefined)).toBe(false); + expect(jasmine.isArray_({})).toBe(false); + expect(jasmine.isArray_(function() {})).toBe(false); + expect(jasmine.isArray_('foo')).toBe(false); + expect(jasmine.isArray_(5)).toBe(false); + expect(jasmine.isArray_(null)).toBe(false); + }); + }); }); diff --git a/src/base.js b/src/base.js index a13a676..fc4837b 100755 --- a/src/base.js +++ b/src/base.js @@ -89,11 +89,7 @@ jasmine.getEnv = function() { * @returns {Boolean} */ jasmine.isArray_ = function(value) { - return value && - typeof value === 'object' && - typeof value.length === 'number' && - typeof value.splice === 'function' && - !(value.propertyIsEnumerable('length')); + return Object.prototype.toString.apply(value) === '[object Array]'; }; /**