-
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.
- Loading branch information
1 parent
4f598d2
commit d7b3442
Showing
1 changed file
with
27 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,27 @@ | ||
import test from 'ava'; | ||
import eachIndex from '.'; | ||
|
||
test('passes the index of each item to the callback', t => { | ||
const results = []; | ||
const callback = x => results.push(x); | ||
|
||
eachIndex([1, 2, 3, 4, 5], callback); | ||
|
||
t.deepEqual(results, [0, 1, 2, 3, 4]); | ||
}); | ||
|
||
test('returns the given array', t => { | ||
const results = []; | ||
const callback = x => results.push(x); | ||
|
||
const array = [1, 2, 3, 4, 5]; | ||
|
||
t.is(array, eachIndex(array, callback)); | ||
}); | ||
|
||
test('throws TypeError if callback is not provided', t => { | ||
const error = t.throws(() => { | ||
eachIndex([1, 2, 3, 4, 5]); | ||
}, TypeError); | ||
t.is(error.message, 'Parameter "callback" must be a function.'); | ||
}); |