mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 01:47:48 +00:00
Add initial test files from lodash v4. (#4172)
* Install test dependencies. * Add initial test files. These files were created using a simplistic AST manipulator using `recast` to preserve formatting. There's bound to be a huge chunk of errors, but this serves as a good start. QUnit was replaced with Mocha, with ES2015 imports running via `esm`. As far as possible, QUnit-specific syntax has been replaced with Mocha's `describe` and `it`, while the native Node.js `assert` module is used for assertions. Files in the `test` directory ending in `.test.js` will be treated as test files. * Add initial passing files to test run.
This commit is contained in:
committed by
John-David Dalton
parent
7606ea3e25
commit
d5ef31929a
72
test/unzip-and-zip.js
Normal file
72
test/unzip-and-zip.js
Normal file
@@ -0,0 +1,72 @@
|
||||
import assert from 'assert';
|
||||
import lodashStable from 'lodash';
|
||||
import { _, falsey, stubArray } from './utils.js';
|
||||
|
||||
describe('unzip and zip', function() {
|
||||
lodashStable.each(['unzip', 'zip'], function(methodName, index) {
|
||||
var func = _[methodName];
|
||||
func = lodashStable.bind(index ? func.apply : func.call, func, null);
|
||||
|
||||
var 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, function(pair, key) {
|
||||
it('`_.' + methodName + '` should work with ' + key, function() {
|
||||
var actual = func(pair[0]);
|
||||
assert.deepStrictEqual(actual, pair[1]);
|
||||
assert.deepStrictEqual(func(actual), actual.length ? pair[0] : []);
|
||||
});
|
||||
});
|
||||
|
||||
it('`_.' + methodName + '` should work with tuples of different lengths', function() {
|
||||
var pair = [
|
||||
[['barney', 36], ['fred', 40, false]],
|
||||
[['barney', 'fred'], [36, 40], [undefined, false]]
|
||||
];
|
||||
|
||||
var actual = func(pair[0]);
|
||||
assert.ok('0' in actual[2]);
|
||||
assert.deepStrictEqual(actual, pair[1]);
|
||||
|
||||
actual = func(actual);
|
||||
assert.ok('2' in actual[0]);
|
||||
assert.deepStrictEqual(actual, [['barney', 36, undefined], ['fred', 40, false]]);
|
||||
});
|
||||
|
||||
it('`_.' + methodName + '` should treat falsey values as empty arrays', function() {
|
||||
var expected = lodashStable.map(falsey, stubArray);
|
||||
|
||||
var actual = lodashStable.map(falsey, function(value) {
|
||||
return func([value, value, value]);
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function() {
|
||||
var array = [[1, 2], [3, 4], null, undefined, { '0': 1 }];
|
||||
assert.deepStrictEqual(func(array), [[1, 3], [2, 4]]);
|
||||
});
|
||||
|
||||
it('`_.' + methodName + '` should support consuming its return value', function() {
|
||||
var expected = [['barney', 'fred'], [36, 40]];
|
||||
assert.deepStrictEqual(func(func(func(func(expected)))), expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user