UNPKG

1.39 kBJavaScriptView Raw
1describe('indexFilter',function() {
2 var ngFilters = factory('filters/ng-filters');
3 var module = factory('filters/index',{
4 'filters/ng-filters': ngFilters,
5 'services/log': logMock
6 });
7
8 var index;
9
10 beforeEach(function() {
11 angular.mock.module(module.name);
12 angular.mock.inject(function(indexFilter) {
13 index = indexFilter;
14 });
15 });
16
17 it('should assign an index to all elements',function() {
18 var list = [{name:'foo'},{name:'bar'}];
19 expect(index(list)).toEqual([{
20 name: 'foo',
21 index: 0
22 },{
23 name: 'bar',
24 index: 1
25 }]);
26 });
27
28 it('should assign an index to all elements to a specified prop',function() {
29 var list = [{name:'foo'},{name:'bar'}];
30 expect(index(list,'murk')).toEqual([{
31 name: 'foo',
32 murk: 0
33 },{
34 name: 'bar',
35 murk: 1
36 }]);
37 });
38
39 describe('testing with non-array arguments',function() {
40 it('should work with strings',function() {
41 expect(index('foo')).toEqual('foo');
42 });
43 it('should work with numbers',function() {
44 expect(index(42)).toEqual(42);
45 });
46 it('should work with undefined',function() {
47 expect(index(undefined)).toBeUndefined();
48 });
49 });
50});