ts-prime
Version:
A utility library for JavaScript and Typescript.
32 lines (31 loc) • 1.12 kB
JavaScript
import { flatten } from './flatten';
import { pipe } from './pipe';
import { find } from './find';
import { createCounter } from './_counter';
test('flatten', function () {
expect(flatten([[1, 2], 3, [4, 5]])).toEqual([1, 2, 3, 4, 5]);
});
test('nested', function () {
expect(flatten([
[1, 2],
[[3], [4, 5]],
])).toEqual([1, 2, [3], [4, 5]]);
});
describe('pipe', function () {
test('flatten multiple values', function () {
var result = pipe([[1, 2], 3, [4, 5]], flatten());
expect(result).toEqual([1, 2, 3, 4, 5]);
});
test('flatten single value', function () {
var result = pipe([[1]], flatten());
expect(result).toEqual([1]);
});
test('with find', function () {
var counter1 = createCounter();
var counter2 = createCounter();
var result = pipe([[1, 2], 3, [4, 5]], counter1.fn(), flatten(), counter2.fn(), find(function (x) { return x - 1 === 2; }));
expect(counter1.count).toHaveBeenCalledTimes(2);
expect(counter2.count).toHaveBeenCalledTimes(3);
expect(result).toEqual(3);
});
});