Test migration to jest by hand
Apparently using regular expressions is way easier.
This commit is contained in:
8
test/invertKeyValues/invertKeyValues.js
Normal file
8
test/invertKeyValues/invertKeyValues.js
Normal file
@ -0,0 +1,8 @@
|
||||
const invertKeyValues = (obj, fn) =>
|
||||
Object.keys(obj).reduce((acc, key) => {
|
||||
const val = fn ? fn(obj[key]) : obj[key];
|
||||
acc[val] = acc[val] || [];
|
||||
acc[val].push(key);
|
||||
return acc;
|
||||
}, {
|
||||
module.exports = invertKeyValues;
|
||||
10
test/invertKeyValues/invertKeyValues.test.js
Normal file
10
test/invertKeyValues/invertKeyValues.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const invertKeyValues = require('./invertKeyValues.js');
|
||||
|
||||
|
||||
test('invertKeyValues is a Function', () => {
|
||||
expect(invertKeyValues).toBeInstanceOf(Function);
|
||||
});
|
||||
t.deepEqual(invertKeyValues({ a: 1, b: 2, c: 1 }), { 1: [ 'a', 'c' ], 2: [ 'b' ] }, "invertKeyValues({ a: 1, b: 2, c: 1 }) returns { 1: [ 'a', 'c' ], 2: [ 'b' ] }");
|
||||
t.deepEqual(invertKeyValues({ a: 1, b: 2, c: 1 }, value => 'group' + value), { group1: [ 'a', 'c' ], group2: [ 'b' ] }, "invertKeyValues({ a: 1, b: 2, c: 1 }, value => 'group' + value) returns { group1: [ 'a', 'c' ], group2: [ 'b' ] }");
|
||||
|
||||
Reference in New Issue
Block a user