mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 01:57:50 +00:00
wip: code formatting nits continued
This commit is contained in:
39
test/fromPairs.spec.js
Normal file
39
test/fromPairs.spec.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import lodashStable from 'lodash';
|
||||
import { falsey, stubObject } from './utils';
|
||||
import fromPairs from '../src/fromPairs';
|
||||
import toPairs from '../src/toPairs';
|
||||
|
||||
describe('fromPairs', () => {
|
||||
it('should accept a two dimensional array', () => {
|
||||
const array = [
|
||||
['a', 1],
|
||||
['b', 2],
|
||||
];
|
||||
const object = { a: 1, b: 2 };
|
||||
const actual = fromPairs(array);
|
||||
|
||||
expect(actual).toEqual(object);
|
||||
});
|
||||
|
||||
it('should accept a falsey `array`', () => {
|
||||
const expected = lodashStable.map(falsey, stubObject);
|
||||
|
||||
const actual = lodashStable.map(falsey, (array, index) => {
|
||||
try {
|
||||
return index ? fromPairs(array) : fromPairs();
|
||||
} catch (e) {}
|
||||
});
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should not support deep paths', () => {
|
||||
const actual = fromPairs([['a.b', 1]]);
|
||||
expect(actual).toEqual({ 'a.b': 1 });
|
||||
});
|
||||
|
||||
it('should support consuming the return value of `_.toPairs`', () => {
|
||||
const object = { 'a.b': 1 };
|
||||
expect(fromPairs(toPairs(object))).toEqual(object);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user