mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 08:37:49 +00:00
* test: fix throttle.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix pickBy.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix isBuffer.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: partially fix attempt.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: partially fix dropRightWhile.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix defer.spec.js and rest.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix invoke.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix isArray.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: partially fix iteration-methods.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix xor-methods.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix property.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix ary.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix omit-methods.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix debounce-and-throttle.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix unzip-and-zip.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix toPairs-methods.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix exit-early.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: temporarily comment out takeWhile and dropWhile tests Signed-off-by: tison <wander4096@gmail.com> * test: partially fix union*.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix startsWith-and-endsWith.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix isNil.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix some of syntax errors Signed-off-by: tison <wander4096@gmail.com> --------- Signed-off-by: tison <wander4096@gmail.com>
93 lines
2.9 KiB
JavaScript
93 lines
2.9 KiB
JavaScript
import lodashStable from 'lodash';
|
|
import { _, falsey, stubArray } from './utils';
|
|
|
|
describe('unzip and zip', () => {
|
|
lodashStable.each(['unzip', 'zip'], (methodName, index) => {
|
|
let func = _[methodName];
|
|
func = lodashStable.bind(index ? func.apply : func.call, func, null);
|
|
|
|
const object = {
|
|
'an empty array': [[], []],
|
|
'0-tuples': [[[], []], []],
|
|
'2-tuples': [
|
|
[
|
|
['barney', 'fred'],
|
|
[36, 40],
|
|
],
|
|
[
|
|
['barney', 36],
|
|
['fred', 40],
|
|
],
|
|
],
|
|
'3-tuples': [
|
|
[
|
|
['barney', 'fred'],
|
|
[36, 40],
|
|
[false, true],
|
|
],
|
|
[
|
|
['barney', 36, false],
|
|
['fred', 40, true],
|
|
],
|
|
],
|
|
};
|
|
|
|
lodashStable.forOwn(object, (pair, key) => {
|
|
it(`\`_.${methodName}\` should work with ${key}`, () => {
|
|
const actual = func(pair[0]);
|
|
expect(actual).toEqual(pair[1]);
|
|
expect(func(actual)).toEqual(actual.length ? pair[0] : []);
|
|
});
|
|
});
|
|
|
|
it(`\`_.${methodName}\` should work with tuples of different lengths`, () => {
|
|
const pair = [
|
|
[
|
|
['barney', 36],
|
|
['fred', 40, false],
|
|
],
|
|
[
|
|
['barney', 'fred'],
|
|
[36, 40],
|
|
[undefined, false],
|
|
],
|
|
];
|
|
|
|
let actual = func(pair[0]);
|
|
expect('0' in actual[2]).toBeTruthy();
|
|
expect(actual).toEqual(pair[1]);
|
|
|
|
actual = func(actual);
|
|
expect('2' in actual[0]).toBeTruthy();
|
|
expect(actual).toEqual([
|
|
['barney', 36, undefined],
|
|
['fred', 40, false],
|
|
]);
|
|
});
|
|
|
|
it(`\`_.${methodName}\` should treat falsey values as empty arrays`, () => {
|
|
const expected = lodashStable.map(falsey, stubArray);
|
|
|
|
const actual = lodashStable.map(falsey, (value) => func([value, value, value]));
|
|
|
|
expect(actual).toEqual(expected);
|
|
});
|
|
|
|
it(`\`_.${methodName}\` should ignore values that are not arrays or \`arguments\` objects`, () => {
|
|
const array = [[1, 2], [3, 4], null, undefined, { 0: 1 }];
|
|
expect(func(array)).toEqual([
|
|
[1, 3],
|
|
[2, 4],
|
|
]);
|
|
});
|
|
|
|
it(`\`_.${methodName}\` should support consuming its return value`, () => {
|
|
const expected = [
|
|
['barney', 'fred'],
|
|
[36, 40],
|
|
];
|
|
expect(func(func(func(func(expected))))).toEqual(expected);
|
|
});
|
|
});
|
|
});
|