mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 07:17:50 +00:00
* 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.
53 lines
1.7 KiB
JavaScript
53 lines
1.7 KiB
JavaScript
import assert from 'assert';
|
|
import lodashStable from 'lodash';
|
|
import { args, toArgs } from './utils.js';
|
|
import pick from '../pick.js';
|
|
|
|
describe('pick', function() {
|
|
var args = toArgs(['a', 'c']),
|
|
object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
|
|
nested = { 'a': 1, 'b': { 'c': 2, 'd': 3 } };
|
|
|
|
it('should flatten `paths`', function() {
|
|
assert.deepStrictEqual(pick(object, 'a', 'c'), { 'a': 1, 'c': 3 });
|
|
assert.deepStrictEqual(pick(object, ['a', 'd'], 'c'), { 'a': 1, 'c': 3, 'd': 4 });
|
|
});
|
|
|
|
it('should support deep paths', function() {
|
|
assert.deepStrictEqual(pick(nested, 'b.c'), { 'b': { 'c': 2 } });
|
|
});
|
|
|
|
it('should support path arrays', function() {
|
|
var object = { 'a.b': 1, 'a': { 'b': 2 } },
|
|
actual = pick(object, [['a.b']]);
|
|
|
|
assert.deepStrictEqual(actual, { 'a.b': 1 });
|
|
});
|
|
|
|
it('should pick a key over a path', function() {
|
|
var object = { 'a.b': 1, 'a': { 'b': 2 } };
|
|
|
|
lodashStable.each(['a.b', ['a.b']], function(path) {
|
|
assert.deepStrictEqual(pick(object, path), { 'a.b': 1 });
|
|
});
|
|
});
|
|
|
|
it('should coerce `paths` to strings', function() {
|
|
assert.deepStrictEqual(pick({ '0': 'a', '1': 'b' }, 0), { '0': 'a' });
|
|
});
|
|
|
|
it('should return an empty object when `object` is nullish', function() {
|
|
lodashStable.each([null, undefined], function(value) {
|
|
assert.deepStrictEqual(pick(value, 'valueOf'), {});
|
|
});
|
|
});
|
|
|
|
it('should work with a primitive `object`', function() {
|
|
assert.deepStrictEqual(pick('', 'slice'), { 'slice': ''.slice });
|
|
});
|
|
|
|
it('should work with `arguments` object `paths`', function() {
|
|
assert.deepStrictEqual(pick(object, args), { 'a': 1, 'c': 3 });
|
|
});
|
|
});
|