From 96a1df192a167e6e34988af687693506f4efd1d1 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Sun, 27 Mar 2011 15:58:24 -0700 Subject: extend size() to take ownPropsOnly param - extend size() to take size(obj, ownPropsOnly) - add specs for size() - update docs to mention string support - use size() in ng:repeat including the hasOwnProp check for all object doesn't create significant perf penalty: http://jsperf.com/dedicated-code-branch-for-hasownprop --- test/AngularSpec.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/AngularSpec.js') diff --git a/test/AngularSpec.js b/test/AngularSpec.js index cbae0606..0a290381 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -110,6 +110,32 @@ describe('angular', function(){ }); }); + + describe('size', function() { + it('should return the number of items in an array', function() { + expect(size([])).toBe(0); + expect(size(['a', 'b', 'c'])).toBe(3); + }); + + it('should return the number of properties of an object', function() { + expect(size({})).toBe(0); + expect(size({a:1, b:'a', c:noop})).toBe(3); + }); + + it('should return the number of own properties of an object', function() { + var obj = inherit({protoProp: 'c', protoFn: noop}, {a:1, b:'a', c:noop}); + + expect(size(obj)).toBe(5); + expect(size(obj, true)).toBe(3); + }); + + it('should return the string length', function() { + expect(size('')).toBe(0); + expect(size('abc')).toBe(3); + }); + }); + + describe('parseKeyValue', function() { it('should parse a string into key-value pairs', function() { expect(parseKeyValue('')).toEqual({}); -- cgit v1.2.3