mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 17:47:49 +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
47
test/fromPairs.js
Normal file
47
test/fromPairs.js
Normal file
@@ -0,0 +1,47 @@
|
||||
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)));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user