Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

style(filterSpec): fix white-space and newline inconsistencies #9765

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions test/ng/filter/filterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('Filter: filter', function() {
filter = $filter('filter');
}));


it('should filter by string', function() {
var items = ['MIsKO', {name: 'shyam'}, ['adam'], 1234];
expect(filter(items, '').length).toBe(4);
Expand All @@ -27,13 +28,15 @@ describe('Filter: filter', function() {
expect(filter(items, "I don't exist").length).toBe(0);
});


it('should not read $ properties', function() {
expect(''.charAt(0)).toBe(''); // assumption

var items = [{$name: 'misko'}];
expect(filter(items, 'misko').length).toBe(0);
});


it('should filter on specific property', function() {
var items = [{ignore: 'a', name: 'a'}, {ignore: 'a', name: 'abc'}];
expect(filter(items, {}).length).toBe(2);
Expand All @@ -44,11 +47,13 @@ describe('Filter: filter', function() {
expect(filter(items, {name: 'b'})[0].name).toBe('abc');
});


it('should take function as predicate', function() {
var items = [{name: 'a'}, {name: 'abc', done: true}];
expect(filter(items, function(i) {return i.done;}).length).toBe(1);
});


it('should pass the index to a function predicate', function() {
var items = [0, 1, 2, 3];

Expand All @@ -59,6 +64,7 @@ describe('Filter: filter', function() {
expect(result).toEqual([0, 2]);
});


it('should take object as predicate', function() {
var items = [{first: 'misko', last: 'hevery'},
{first: 'adam', last: 'abrons'}];
Expand Down Expand Up @@ -103,17 +109,19 @@ describe('Filter: filter', function() {
expect(filter(items, {$: 'hevery'})[0]).toEqual(items[0]);
});


it('should support boolean properties', function() {
var items = [{name: 'tom', current: true},
{name: 'demi', current: false},
{name: 'sofia'}];
{name: 'demi', current: false},
{name: 'sofia'}];

expect(filter(items, {current:true}).length).toBe(1);
expect(filter(items, {current:true})[0].name).toBe('tom');
expect(filter(items, {current:false}).length).toBe(1);
expect(filter(items, {current:false})[0].name).toBe('demi');
});


it('should support negation operator', function() {
var items = ['misko', 'adam'];

Expand All @@ -133,8 +141,8 @@ describe('Filter: filter', function() {
{key: 'value1', nonkey: 1},
{key: 'value2', nonkey: 2},
{key: 'value12', nonkey: 3},
{key: 'value1', nonkey:4},
{key: 'Value1', nonkey:5}
{key: 'value1', nonkey: 4},
{key: 'Value1', nonkey: 5}
];
expr = {key: 'value1'};
expect(filter(items, expr, true)).toEqual([items[0], items[3]]);
Expand All @@ -143,21 +151,22 @@ describe('Filter: filter', function() {
{key: 1, nonkey: 1},
{key: 2, nonkey: 2},
{key: 12, nonkey: 3},
{key: 1, nonkey:4}
{key: 1, nonkey: 4}
];
expr = { key: 1 };
expr = {key: 1};
expect(filter(items, expr, true)).toEqual([items[0], items[3]]);

expr = 12;
expect(filter(items, expr, true)).toEqual([items[2]]);
});


it('and use the function given to compare values', function() {
var items = [
{key: 1, nonkey: 1},
{key: 2, nonkey: 2},
{key: 12, nonkey: 3},
{key: 1, nonkey:14}
{key: 1, nonkey: 14}
];
var expr = {key: 10};
var comparator = function(obj, value) {
Expand All @@ -167,10 +176,6 @@ describe('Filter: filter', function() {

expr = 10;
expect(filter(items, expr, comparator)).toEqual([items[2], items[3]]);

});


});

});