UNPKG

ts-prime

Version:

A utility library for JavaScript and Typescript.

35 lines (34 loc) 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var find_1 = require("./find"); var pipe_1 = require("./pipe"); var _counter_1 = require("./_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_1.find(array, function (x) { return x.b === 2; })).toEqual(expected); }); test('find.indexed', function () { expect(find_1.find.indexed(array, function (x, idx) { return x.b === 2 && idx === 1; })).toEqual(expected); }); }); describe('data last', function () { test('find', function () { var counter = _counter_1.createCounter(); var actual = pipe_1.pipe(array, counter.fn(), find_1.find(function (x) { return x.b === 2; })); expect(counter.count).toHaveBeenCalledTimes(2); expect(actual).toEqual(expected); }); test('find.indexed', function () { var counter = _counter_1.createCounter(); var actual = pipe_1.pipe(array, counter.fn(), find_1.find.indexed(function (x, idx) { return x.b === 2 && idx === 1; })); expect(counter.count).toHaveBeenCalledTimes(2); expect(actual).toEqual(expected); }); });