Files
lodash/test/union-methods.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

32 lines
1.2 KiB
JavaScript

import assert from 'assert';
import lodashStable from 'lodash';
import { _, args } from './utils.js';
describe('union methods', function() {
lodashStable.each(['union', 'unionBy', 'unionWith'], function(methodName) {
var func = _[methodName];
it('`_.' + methodName + '` should return the union of two arrays', function() {
var actual = func([2], [1, 2]);
assert.deepStrictEqual(actual, [2, 1]);
});
it('`_.' + methodName + '` should return the union of multiple arrays', function() {
var actual = func([2], [1, 2], [2, 3]);
assert.deepStrictEqual(actual, [2, 1, 3]);
});
it('`_.' + methodName + '` should not flatten nested arrays', function() {
var actual = func([1, 3, 2], [1, [5]], [2, [4]]);
assert.deepStrictEqual(actual, [1, 3, 2, [5], [4]]);
});
it('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function() {
var array = [0];
assert.deepStrictEqual(func(array, 3, { '0': 1 }, null), array);
assert.deepStrictEqual(func(null, array, null, [2, 1]), [0, 2, 1]);
assert.deepStrictEqual(func(array, null, args, null), [0, 1, 2, 3]);
});
});
});