-
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(every): add tests for every function
- Loading branch information
Sean Hamilton
committed
Dec 3, 2018
1 parent
5a3f20a
commit 5e42af2
Showing
1 changed file
with
69 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,69 @@ | ||
import every from '../src/every'; | ||
|
||
describe('every', () => { | ||
test('should return false if the object specified isn\'t an object', () => { | ||
const equal = every('test', () => {}); | ||
|
||
expect(equal).toBe(false); | ||
}); | ||
|
||
test('should return false if the object specified is empty', () => { | ||
const equal = every({}, () => {}); | ||
|
||
expect(equal).toBe(false); | ||
}); | ||
|
||
test('should return false if the iterator isn\'t provided', () => { | ||
const equal = every({}); | ||
|
||
expect(equal).toBe(false); | ||
}); | ||
|
||
test('should return false if the iterator isn\'t a function', () => { | ||
const equal = every({}, 'test'); | ||
|
||
expect(equal).toBe(false); | ||
}); | ||
|
||
test('should return true if all values evaluate to true', () => { | ||
const equal = every({ a: 1, b: 1, c: 1 }, (key, value) => value === 1); | ||
|
||
expect(equal).toBe(true); | ||
}); | ||
|
||
test('should return false if one or more values evaluate to false', () => { | ||
const equal = every({ a: 1, b: 1, c: 2 }, (key, value) => value === 1); | ||
|
||
expect(equal).toBe(false); | ||
}); | ||
|
||
test('should return true if all values including deep object values evaluate to true when follow is true', () => { | ||
const obj = { | ||
a: 1, | ||
b: 1, | ||
c: 1, | ||
d: { | ||
e: 1, | ||
}, | ||
}; | ||
|
||
const equal = every(obj, (key, value) => value === 1, true); | ||
|
||
expect(equal).toBe(true); | ||
}); | ||
|
||
test('should return false if one or more values including deep object values evaluate to false when follow is true', () => { | ||
const obj = { | ||
a: 1, | ||
b: 1, | ||
c: 1, | ||
d: { | ||
e: 2, | ||
}, | ||
}; | ||
|
||
const equal = every(obj, (key, value) => value === 1, true); | ||
|
||
expect(equal).toBe(false); | ||
}); | ||
}); |