-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(filter): add tests for filter function
- Loading branch information
Sean Hamilton
committed
Dec 3, 2018
1 parent
e8d9c3f
commit 047ac91
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import filter from '../src/filter'; | ||
|
||
describe('every', () => { | ||
test('should return an empty object if the object specified isn\'t an object', () => { | ||
const filtered = filter('test', () => {}); | ||
|
||
expect(typeof filtered).toBe('object'); | ||
}); | ||
|
||
test('should return an empty object if the object specified is empty', () => { | ||
const filtered = filter({}, () => {}); | ||
|
||
expect(typeof filtered).toBe('object'); | ||
}); | ||
|
||
test('should return an empty object if the iterator isn\'t provided', () => { | ||
const filtered = filter({}); | ||
|
||
expect(typeof filtered).toBe('object'); | ||
}); | ||
|
||
test('should return an empty object if the iterator isn\'t a function', () => { | ||
const filtered = filter({}, 'test'); | ||
|
||
expect(typeof filtered).toBe('object'); | ||
}); | ||
|
||
test('should return the filtered values', () => { | ||
const obj = { | ||
a: 1, | ||
b: 2, | ||
c: 3, | ||
}; | ||
const filtered = filter(obj, (key, value) => value > 2); | ||
|
||
expect(Object.keys(filtered).length).toBe(1); | ||
}); | ||
|
||
test('should return the filtered values including deep object values when follow is true', () => { | ||
const obj = { | ||
a: 1, | ||
b: 2, | ||
c: 3, | ||
d: { | ||
e: 4, | ||
f: 5, | ||
}, | ||
}; | ||
const filtered = filter(obj, (key, value) => value > 2, true); | ||
|
||
expect(Object.keys(filtered).length).toBe(2); | ||
}); | ||
|
||
test('should return the filtered values without filtering deep object values when follow is false', () => { | ||
const obj = { | ||
a: 1, | ||
b: 2, | ||
c: 3, | ||
d: { | ||
e: 4, | ||
f: 5, | ||
}, | ||
}; | ||
const filtered = filter(obj, (key, value) => value > 2, false); | ||
|
||
expect(Object.keys(filtered).length).toBe(1); | ||
}); | ||
}); |