1import { set, get, pickBy } from '../obj'; 2 3describe(set, () => { 4 it(`sets deeply`, () => { 5 expect(set({}, 'a.b.c', 'd')).toEqual({ a: { b: { c: 'd' } } }); 6 }); 7 it(`overwrites`, () => { 8 expect(set({ a: { b: { c: 'e' } } }, 'a.b.c', 'd')).toEqual({ a: { b: { c: 'd' } } }); 9 }); 10 it(`shallow writes`, () => { 11 expect(set({}, 'a', 'd')).toEqual({ a: 'd' }); 12 }); 13}); 14describe(get, () => { 15 it(`gets deeply`, () => { 16 expect(get({ a: { b: { c: 'd' } } }, 'a.b.c')).toEqual('d'); 17 }); 18 it(`returns null`, () => { 19 expect(get({ a: { b: { c: 'd' } } }, 'a.b.d')).toEqual(null); 20 }); 21}); 22 23describe(pickBy, () => { 24 it(`picks`, () => { 25 expect(pickBy({ a: { b: { c: 'd' } } }, (_, key) => key.startsWith('a'))).toEqual({ 26 a: { b: { c: 'd' } }, 27 }); 28 }); 29 it(`ignores`, () => { 30 expect(pickBy({ a: { b: { c: 'd' } } }, (_, key) => !key.startsWith('a'))).toEqual({}); 31 }); 32}); 33