From efec0c358d3cb840275037d5f86347130bb86573 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Mon, 22 Nov 2010 10:23:45 -0800 Subject: Add angular.Array.limitTo and docs for angular.Array --- test/ApiSpecs.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test') diff --git a/test/ApiSpecs.js b/test/ApiSpecs.js index 81fd9155..e2a68a61 100644 --- a/test/ApiSpecs.js +++ b/test/ApiSpecs.js @@ -115,6 +115,36 @@ describe('api', function(){ }); + describe('limit', function() { + var items; + + beforeEach(function() { + items = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; + }); + + + it('should return the first X items when X is positive', function() { + expect(angular.Array.limitTo(items, 3)).toEqual(['a', 'b', 'c']); + expect(angular.Array.limitTo(items, '3')).toEqual(['a', 'b', 'c']); + }); + + + it('should return the last X items when X is negative', function() { + expect(angular.Array.limitTo(items, -3)).toEqual(['f', 'g', 'h']); + expect(angular.Array.limitTo(items, '-3')).toEqual(['f', 'g', 'h']); + }); + + + it('should return an empty array when X cannot be parsed', function() { + expect(angular.Array.limitTo(items, 'bogus')).toEqual([]); + expect(angular.Array.limitTo(items, 'null')).toEqual([]); + expect(angular.Array.limitTo(items, 'undefined')).toEqual([]); + expect(angular.Array.limitTo(items, null)).toEqual([]); + expect(angular.Array.limitTo(items, undefined)).toEqual([]); + }) + }); + + it('Add', function(){ var add = angular.Array.add; assertJsonEquals([{}, "a"], add(add([]),"a")); -- cgit v1.2.3