diff options
| author | Jeremy Tymes | 2012-12-05 07:41:11 -0500 |
|---|---|---|
| committer | Pawel Kozlowski | 2012-12-19 20:13:36 +0100 |
| commit | 9e96d983451899ef0cef3e68395c8f6c1ef83bbe (patch) | |
| tree | e4c3a8d478f8f2a676b33d914396c3712c94bc57 /test | |
| parent | 1e13544da8c8ca8c630fd14feca25ab1b40bd3fd (diff) | |
| download | angular.js-9e96d983451899ef0cef3e68395c8f6c1ef83bbe.tar.bz2 | |
feat(limitTo): limitTo filter accepts strings
This allows strings to be filtered by limitTo, using the same methods
Closes #653
Diffstat (limited to 'test')
| -rw-r--r-- | test/ng/filter/limitToSpec.js | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/test/ng/filter/limitToSpec.js b/test/ng/filter/limitToSpec.js index b0977235..2ebdc214 100644 --- a/test/ng/filter/limitToSpec.js +++ b/test/ng/filter/limitToSpec.js @@ -2,10 +2,12 @@ describe('Filter: limitTo', function() { var items; + var str var limitTo; beforeEach(inject(function($filter) { items = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; + str = "tuvwxyz"; limitTo = $filter('limitTo'); })); @@ -13,12 +15,16 @@ describe('Filter: limitTo', function() { it('should return the first X items when X is positive', function() { expect(limitTo(items, 3)).toEqual(['a', 'b', 'c']); expect(limitTo(items, '3')).toEqual(['a', 'b', 'c']); + expect(limitTo(str, 3)).toEqual("tuv"); + expect(limitTo(str, '3')).toEqual("tuv"); }); it('should return the last X items when X is negative', function() { expect(limitTo(items, -3)).toEqual(['f', 'g', 'h']); expect(limitTo(items, '-3')).toEqual(['f', 'g', 'h']); + expect(limitTo(str, -3)).toEqual("xyz"); + expect(limitTo(str, '-3')).toEqual("xyz"); }); @@ -30,11 +36,17 @@ describe('Filter: limitTo', function() { expect(limitTo(items, undefined)).toEqual([]); }); + it('should return an empty string when X cannot be parsed', function() { + expect(limitTo(str, 'bogus')).toEqual(""); + expect(limitTo(str, 'null')).toEqual(""); + expect(limitTo(str, 'undefined')).toEqual(""); + expect(limitTo(str, null)).toEqual(""); + expect(limitTo(str, undefined)).toEqual(""); + }); - it('should return an empty array when input is not Array type', function() { - expect(limitTo('bogus', 1)).toEqual('bogus'); - expect(limitTo(null, 1)).toEqual(null); - expect(limitTo(undefined, 1)).toEqual(undefined); + + it('should return input if not String or Array', function() { + expect(limitTo(1,1)).toEqual(1); expect(limitTo(null, 1)).toEqual(null); expect(limitTo(undefined, 1)).toEqual(undefined); expect(limitTo({}, 1)).toEqual({}); @@ -42,11 +54,18 @@ describe('Filter: limitTo', function() { it('should return a copy of input array if X is exceeds array length', function () { - expect(limitTo(items, 19)).toEqual(items); + expect(limitTo(items, 9)).toEqual(items); expect(limitTo(items, '9')).toEqual(items); expect(limitTo(items, -9)).toEqual(items); expect(limitTo(items, '-9')).toEqual(items); expect(limitTo(items, 9)).not.toBe(items); }); + + it('should return the entire string if X exceeds input length', function() { + expect(limitTo(str, 9)).toEqual(str); + expect(limitTo(str, '9')).toEqual(str); + expect(limitTo(str, -9)).toEqual(str); + expect(limitTo(str, '-9')).toEqual(str); + }) }); |
