Skip to content

Commit

Permalink
Add tests for .eachIndex() method
Browse files Browse the repository at this point in the history
  • Loading branch information
arnellebalane authored and aldnav committed Jun 1, 2019
1 parent 4f598d2 commit d7b3442
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions methods/eachIndex/tests.js
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.');
});

0 comments on commit d7b3442

Please sign in to comment.