|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +describe('isJoinFilter', function () { |
| 4 | + var joinFilter; |
| 5 | + |
| 6 | + beforeEach(module('a8m.join')); |
| 7 | + |
| 8 | + beforeEach(inject(function (_joinFilter_) { |
| 9 | + joinFilter = _joinFilter_; |
| 10 | + })); |
| 11 | + |
| 12 | + describe('given a collection', function () { |
| 13 | + var arr; |
| 14 | + |
| 15 | + describe('which is empty', function () { |
| 16 | + beforeEach(function () { |
| 17 | + arr = []; |
| 18 | + }); |
| 19 | + |
| 20 | + it('should return an empty string', function () { |
| 21 | + expect(joinFilter(arr)).toEqual(''); |
| 22 | + }); |
| 23 | + |
| 24 | + }); |
| 25 | + |
| 26 | + describe('of strings', function () { |
| 27 | + beforeEach(function () { |
| 28 | + arr = ['hello', 'world']; |
| 29 | + }); |
| 30 | + |
| 31 | + describe('with no delimiter', function () { |
| 32 | + it('should join elements with a space', function () { |
| 33 | + expect(joinFilter(arr)).toEqual('hello world'); |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + describe('with a custom delimiter', function () { |
| 38 | + var delim; |
| 39 | + |
| 40 | + describe('which is not a string', function () { |
| 41 | + it('should join elements with a toString representation of the delimiter', function () { |
| 42 | + delim = true; |
| 43 | + expect(joinFilter(arr, delim)).toEqual('hellotrueworld'); |
| 44 | + |
| 45 | + delim = 10; |
| 46 | + expect(joinFilter(arr, delim)).toEqual('hello10world'); |
| 47 | + |
| 48 | + delim = {toString: function () { return ' - ' }} |
| 49 | + expect(joinFilter(arr, delim)).toEqual('hello - world'); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should join elements with the given delimiter', function () { |
| 54 | + delim = ', ' |
| 55 | + expect(joinFilter(arr, delim)).toEqual('hello, world'); |
| 56 | + }); |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + }); |
| 61 | + |
| 62 | + describe('given something that is not a collection', function () { |
| 63 | + var str, obj, bool, num; |
| 64 | + beforeEach(function () { |
| 65 | + str = 'string'; |
| 66 | + obj = {'a': 'b'}; |
| 67 | + bool = true; |
| 68 | + num = 5; |
| 69 | + }); |
| 70 | + |
| 71 | + it('should return the input as is', function () { |
| 72 | + expect(joinFilter(str)).toEqual(str); |
| 73 | + expect(joinFilter(obj)).toEqual(obj); |
| 74 | + expect(joinFilter(bool)).toEqual(bool); |
| 75 | + expect(joinFilter(num)).toEqual(num); |
| 76 | + }); |
| 77 | + }); |
| 78 | +}); |
0 commit comments