-
Notifications
You must be signed in to change notification settings - Fork 2
/
snakify.test.js
41 lines (33 loc) · 1.24 KB
/
snakify.test.js
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
40
41
const snakify = require('./index')
test('shallow depth', () => {
const given = { shallowDepth: true }
const expected = { shallow_depth: true }
expect(snakify(given)).toEqual(expected)
})
test('deep depth', () => {
const given = { oneDepth: { twoDepth: { threeDepth: true }, twoDepth2: { threeDepth2: false } } }
const expected = { one_depth: { two_depth: { three_depth: true }, two_depth_2: { three_depth_2: false } } }
expect(snakify(given)).toEqual(expected)
})
test('various types', () => {
const given = { numVal: 1, strVal: 'camelCase', boolVal: true, nullValue: null, undefinedValue: undefined }
const expected = { num_val: 1, str_val: 'camelCase', bool_val: true, null_value: null, undefined_value: undefined }
expect(snakify(given)).toEqual(expected)
})
test('array case', () => {
const given = {
arrVal: [ 1, 'camelCaseArrVal', true ],
arrObj: [
{ numVal: 1, strVal: 'camelCase', boolVal: true },
{ numVal: 1, strVal: 'camelCase', boolVal: true },
],
}
const expected = {
arr_val: [ 1, 'camelCaseArrVal', true ],
arr_obj: [
{ num_val: 1, str_val: 'camelCase', bool_val: true },
{ num_val: 1, str_val: 'camelCase', bool_val: true },
],
}
expect(snakify(given)).toEqual(expected)
})