mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 17:37:50 +00:00
wip: code formatting nits continued
This commit is contained in:
42
test/invertBy.spec.js
Normal file
42
test/invertBy.spec.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import lodashStable from 'lodash';
|
||||
import invertBy from '../src/invertBy';
|
||||
|
||||
describe('invertBy', () => {
|
||||
const object = { a: 1, b: 2, c: 1 };
|
||||
|
||||
it('should transform keys by `iteratee`', () => {
|
||||
const expected = { group1: ['a', 'c'], group2: ['b'] };
|
||||
|
||||
const actual = invertBy(object, (value) => `group${value}`);
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should use `_.identity` when `iteratee` is nullish', () => {
|
||||
const values = [, null, undefined];
|
||||
const expected = lodashStable.map(
|
||||
values,
|
||||
lodashStable.constant({ 1: ['a', 'c'], 2: ['b'] }),
|
||||
);
|
||||
|
||||
const actual = lodashStable.map(values, (value, index) =>
|
||||
index ? invertBy(object, value) : invertBy(object),
|
||||
);
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should only add multiple values to own, not inherited, properties', () => {
|
||||
const object = { a: 'hasOwnProperty', b: 'constructor' };
|
||||
const expected = { hasOwnProperty: ['a'], constructor: ['b'] };
|
||||
|
||||
expect(lodashStable.isEqual(invertBy(object), expected))
|
||||
});
|
||||
|
||||
it('should return a wrapped value when chaining', () => {
|
||||
const wrapped = _(object).invertBy();
|
||||
|
||||
expect(wrapped instanceof _)
|
||||
expect(wrapped.value(), { 1: ['a', 'c']).toEqual(2: ['b'] });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user