UNPKG

ts-prime

Version:

A utility library for JavaScript and Typescript.

33 lines (32 loc) 1.16 kB
import { find } from './find'; import { pipe } from './pipe'; import { createCounter } from './_counter'; var array = [ { a: 1, b: 1 }, { a: 1, b: 2 }, { a: 2, b: 1 }, { a: 1, b: 3 }, ]; var expected = { a: 1, b: 2 }; describe('data first', function () { test('find', function () { expect(find(array, function (x) { return x.b === 2; })).toEqual(expected); }); test('find.indexed', function () { expect(find.indexed(array, function (x, idx) { return x.b === 2 && idx === 1; })).toEqual(expected); }); }); describe('data last', function () { test('find', function () { var counter = createCounter(); var actual = pipe(array, counter.fn(), find(function (x) { return x.b === 2; })); expect(counter.count).toHaveBeenCalledTimes(2); expect(actual).toEqual(expected); }); test('find.indexed', function () { var counter = createCounter(); var actual = pipe(array, counter.fn(), find.indexed(function (x, idx) { return x.b === 2 && idx === 1; })); expect(counter.count).toHaveBeenCalledTimes(2); expect(actual).toEqual(expected); }); });