This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
tablify.js
121 lines (120 loc) · 3.95 KB
/
tablify.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* LiskHQ/lisk-commander
* Copyright © 2017–2018 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
import * as given from '../../steps/1_given';
import * as when from '../../steps/2_when';
import * as then from '../../steps/3_then';
describe('tablify util', () => {
Given('an empty object', given.anEmptyObject, () => {
When('the object is tablified', when.theObjectIsTablified, () => {
Then(
'the returned table should have no head',
then.theReturnedTableShouldHaveNoHead,
);
Then(
'the returned table should have no rows',
then.theReturnedTableShouldHaveNoRows,
);
});
});
Given('a non-empty object', given.aNonEmptyObject, () => {
When('the object is tablified', when.theObjectIsTablified, () => {
Then(
'the returned table should have a row with the object’s key values',
then.theReturnedTableShouldHaveARowWithTheObjectKeyValues,
);
});
});
Given('an object with object array', given.anObjectWithObjectArray, () => {
When('the object is tablified', when.theObjectIsTablified, () => {
Then(
'the returned table should have a row with the object key and stringified nested values',
then.theReturnedTableShouldHaveARowWithTheObjectKeyAndStringifiedNestedValues,
);
});
});
Given('a nested object', given.aNestedObject, () => {
When('the object is tablified', when.theObjectIsTablified, () => {
Then(
'the returned table should have a row with the object key and stringified nested values',
then.theReturnedTableShouldHaveARowWithTheObjectKeyAndStringifiedNestedValues,
);
});
});
Given('a deeply nested object', given.aDeeplyNestedObject, () => {
When('the object is tablified', when.theObjectIsTablified, () => {
Then(
'the returned table should have a row with the object key and stringified nested values',
then.theReturnedTableShouldHaveARowWithTheObjectKeyAndStringifiedNestedValues,
);
});
});
Given('a cyclic object', given.aCyclicObject, () => {
When('the object is tablified', when.theObjectIsTablified, () => {
Then(
'it should throw type error "Converting circular structure to JSON"',
then.itShouldThrowTypeError,
);
});
});
Given(
'an array of objects with the same keys',
given.anArrayOfObjectsWithTheSameKeys,
() => {
When('the array is tablified', when.theArrayIsTablified, () => {
Then(
'the returned table should have head rows',
then.theReturnedTableShouldHaveHeaderRows,
);
Then(
'the returned table should have rows with the object key and stringified values',
then.theReturnedTableShouldHaveRowsWithTheObjectKeyAndStringifiedValues,
);
});
},
);
Given(
'an array of objects with divergent keys',
given.anArrayOfObjectsWithDivergentKeys,
() => {
When('the array is tablified', when.theArrayIsTablified, () => {
Then(
'the returned table should have head rows',
then.theReturnedTableShouldHaveHeaderRows,
);
Then(
'the returned table should have rows with the object key and stringified values',
then.theReturnedTableShouldHaveRowsWithTheObjectKeyAndStringifiedValues,
);
});
},
);
Given(
'an array of objects with nested keys',
given.anArrayOfObjectsWithNestedKeys,
() => {
When('the array is tablified', when.theArrayIsTablified, () => {
Then(
'the returned table should have head rows',
then.theReturnedTableShouldHaveHeaderRows,
);
Then(
'the returned table should have rows with the object key and stringified values',
then.theReturnedTableShouldHaveRowsWithTheObjectKeyAndStringifiedNestedValues,
);
});
},
);
});