-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
40 lines (31 loc) · 1 KB
/
test.js
File metadata and controls
40 lines (31 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import test from 'ava';
import flatifyObject from './src';
test('throw error on non object types', t => {
t.throws(() => {
flatifyObject(null);
}, {
instanceOf: TypeError,
message: 'Expected a type object, got null'
});
t.throws(() => {
flatifyObject('unicorn');
}, {
instanceOf: TypeError,
message: 'Expected a type object, got string'
});
});
test('main test without any option', t => {
const flattended = flatifyObject({foo: {unicorn: '🦄'}, bar: 'unicorn'});
const expected = {'foo.unicorn': '🦄', bar: 'unicorn'};
t.deepEqual(flattended, expected);
});
test('test nested objects', t => {
const flattended = flatifyObject({foo: {bar: {unicorn: '🦄'}}});
const expected = {'foo.bar.unicorn': '🦄'};
t.deepEqual(flattended, expected);
});
test('with option - onlyLeaves set to true', t => {
const flattended = flatifyObject({foo: {unicorn: '🦄'}, bar: 'unicorn'}, {onlyLeaves: true});
const expected = {unicorn: '🦄', bar: 'unicorn'};
t.deepEqual(flattended, expected);
});