Files
lodash/test/concat.js
Benjamin Tan d5ef31929a 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.
2019-02-12 09:11:32 -08:00

66 lines
1.7 KiB
JavaScript

import assert from 'assert';
import lodashStable from 'lodash';
import concat from '../concat.js';
describe('concat', function() {
it('should shallow clone `array`', function() {
var array = [1, 2, 3],
actual = concat(array);
assert.deepStrictEqual(actual, array);
assert.notStrictEqual(actual, array);
});
it('should concat arrays and values', function() {
var array = [1],
actual = concat(array, 2, [3], [[4]]);
assert.deepStrictEqual(actual, [1, 2, 3, [4]]);
assert.deepStrictEqual(array, [1]);
});
it('should cast non-array `array` values to arrays', function() {
var values = [, null, undefined, false, true, 1, NaN, 'a'];
var expected = lodashStable.map(values, function(value, index) {
return index ? [value] : [];
});
var actual = lodashStable.map(values, function(value, index) {
return index ? concat(value) : concat();
});
assert.deepStrictEqual(actual, expected);
expected = lodashStable.map(values, function(value) {
return [value, 2, [3]];
});
actual = lodashStable.map(values, function(value) {
return concat(value, [2], [[3]]);
});
assert.deepStrictEqual(actual, expected);
});
it('should treat sparse arrays as dense', function() {
var expected = [],
actual = concat(Array(1), Array(1));
expected.push(undefined, undefined);
assert.ok('0'in actual);
assert.ok('1' in actual);
assert.deepStrictEqual(actual, expected);
});
it('should return a new wrapped array', function() {
var array = [1],
wrapped = _(array).concat([2, 3]),
actual = wrapped.value();
assert.deepEqual(array, [1]);
assert.deepEqual(actual, [1, 2, 3]);
});
});