Update isArray_ function and add test coverage

This commit is contained in:
Josh Susser 2010-02-24 19:35:32 -08:00
parent 5e3eb884ca
commit 6ca766d5ea
3 changed files with 20 additions and 11 deletions

View File

@ -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
};

View File

@ -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);
});
});
});

View File

@ -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]';
};
/**