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

48 lines
1.4 KiB
JavaScript

import assert from 'assert';
import lodashStable from 'lodash';
import { falsey, stubObject, LARGE_ARRAY_SIZE } from './utils.js';
import fromPairs from '../fromPairs.js';
import toPairs from '../toPairs.js';
describe('fromPairs', function() {
it('should accept a two dimensional array', function() {
var array = [['a', 1], ['b', 2]],
object = { 'a': 1, 'b': 2 },
actual = fromPairs(array);
assert.deepStrictEqual(actual, object);
});
it('should accept a falsey `array`', function() {
var expected = lodashStable.map(falsey, stubObject);
var actual = lodashStable.map(falsey, function(array, index) {
try {
return index ? fromPairs(array) : fromPairs();
} catch (e) {}
});
assert.deepStrictEqual(actual, expected);
});
it('should not support deep paths', function() {
var actual = fromPairs([['a.b', 1]]);
assert.deepStrictEqual(actual, { 'a.b': 1 });
});
it('should support consuming the return value of `_.toPairs`', function() {
var object = { 'a.b': 1 };
assert.deepStrictEqual(fromPairs(toPairs(object)), object);
});
it('should work in a lazy sequence', function() {
var array = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
return ['key' + index, index];
});
var actual = _(array).fromPairs().map(square).filter(isEven).take().value();
assert.deepEqual(actual, _.take(_.filter(_.map(fromPairs(array), square), isEven)));
});
});