UNPKG

ts-prime

Version:

A utility library for JavaScript and Typescript.

29 lines (28 loc) 1.16 kB
import { findIndex } from './findIndex'; import { pipe } from './pipe'; import { createCounter } from './_counter'; describe('data first', function () { test('findIndex', function () { expect(findIndex([10, 20, 30], function (x) { return x === 20; })).toBe(1); }); test('findIndex.indexed', function () { expect(findIndex([10, 20, 30], function (x) { return x === 20; })).toBe(1); }); test('findIndex -1', function () { expect(findIndex([2, 3, 4], function (x) { return x === 20; })).toBe(-1); }); }); describe('data last', function () { test('findIndex', function () { var counter = createCounter(); var actual = pipe([10, 20, 30], counter.fn(), findIndex(function (x) { return x === 20; })); expect(counter.count).toHaveBeenCalledTimes(2); expect(actual).toEqual(1); }); test('findIndex.indexed', function () { var counter = createCounter(); var actual = pipe([10, 20, 30], counter.fn(), findIndex.indexed(function (x) { return x === 20; })); expect(counter.count).toHaveBeenCalledTimes(2); expect(actual).toEqual(1); }); });