Skip to content

Instantly share code, notes, and snippets.

@jemgold
Created March 1, 2016 08:21
Show Gist options
  • Save jemgold/3428dc082651127b4139 to your computer and use it in GitHub Desktop.
Save jemgold/3428dc082651127b4139 to your computer and use it in GitHub Desktop.
import expect from 'expect';
import { flatten, unflatten } from 'src/flatten';
describe('Flatten', () => {
it('flattens an object, prefixed by original keys', () => {
const input = {
foo: {
bar: 'baz',
qux: 'zip',
},
bar: {
bar: 'baz',
qux: 'zip',
},
};
const expected = {
foo_bar: 'baz',
foo_qux: 'zip',
bar_bar: 'baz',
bar_qux: 'zip',
};
expect(flatten(input)).toEqual(expected);
});
});
describe('Unflatten', () => {
it('Unflattens an object, prefixed by original keys', () => {
const input = {
foo_bar: 'baz',
foo_qux: 'zip',
bar_bar: 'baz',
bar_qux: 'zip',
};
const expected = {
foo: {
bar: 'baz',
qux: 'zip',
},
bar: {
bar: 'baz',
qux: 'zip',
},
};
expect(unflatten(input)).toEqual(expected);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment