UNPKG

@tdb/util

Version:
46 lines (45 loc) 1.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var chai_1 = require("chai"); var _1 = require("."); describe('compact', function () { it('makes no change', function () { chai_1.expect(_1.value.compact([1, 2, 3])).to.eql([1, 2, 3]); }); it('removes null values', function () { chai_1.expect(_1.value.compact([1, null, 3, null])).to.eql([1, 3]); }); it('removes undefined values', function () { chai_1.expect(_1.value.compact([1, undefined, 3, undefined])).to.eql([1, 3]); }); it('removes empty strings', function () { chai_1.expect(_1.value.compact([1, '', 3])).to.eql([1, 3]); }); it('retains `false` and 0', function () { chai_1.expect(_1.value.compact([0, 1, false, 3])).to.eql([0, 1, false, 3]); }); it('retains white space strings', function () { chai_1.expect(_1.value.compact([0, 1, ' ', 3])).to.eql([0, 1, ' ', 3]); }); }); describe('flatten', function () { it('makes no change', function () { chai_1.expect(_1.value.flatten([1, 2, 3])).to.eql([1, 2, 3]); }); it('return input value if an array is not passed', function () { chai_1.expect(_1.value.flatten(123)).to.eql(123); }); it('flattens one level deep', function () { chai_1.expect(_1.value.flatten([1, [2, 3]])).to.eql([1, 2, 3]); }); it('flattens many levels deep', function () { chai_1.expect(_1.value.flatten([1, [2, [3, [4, [5, 6]]]]])).to.eql([ 1, 2, 3, 4, 5, 6, ]); }); });