/
index.test.js
91 lines (72 loc) · 3.8 KB
/
index.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
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
/**
* Module requirements.
*/
require('should');
var Table = require('cli-table');
/**
* Tests.
*/
module.exports = {
'test complete table': function (){
var table = new Table({
head: ['Rel', 'Change', 'By', 'When']
, style: {
'padding-left': 1
, 'padding-right': 1
}
, colWidths: [6, 21, 25, 17]
});
table.push(
['v0.1', 'Testing something cool', 'rauchg@gmail.com', '7 minutes ago']
, ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '8 minutes ago']
);
var expected = [
'┌──────┬─────────────────────┬─────────────────────────┬─────────────────┐'
, '│ Rel │ Change │ By │ When │'
, '├──────┼─────────────────────┼─────────────────────────┼─────────────────┤'
, '│ v0.1 │ Testing something … │ rauchg@gmail.com │ 7 minutes ago │'
, '├──────┼─────────────────────┼─────────────────────────┼─────────────────┤'
, '│ v0.1 │ Testing something … │ rauchg@gmail.com │ 8 minutes ago │'
, '└──────┴─────────────────────┴─────────────────────────┴─────────────────┘'
];
table.toString().should.eql(expected.join("\n"));
},
'test width property': function (){
var table = new Table({
head: ['Cool']
});
table.width.should.eql(8);
},
'test vertical table output': function() {
var table = new Table({ style: {} }); // clear styles to prevent color output
table.push(
{'v0.1': 'Testing something cool'}
, {'v0.1': 'Testing something cool'}
);
var expected = [
'┌─────────┬──────────────────────┐'
, '│v0.1 │Testing something cool│'
, '├─────────┼──────────────────────┤'
, '│v0.1 │Testing something cool│'
, '└─────────┴──────────────────────┘'
];
table.toString().should.eql(expected.join("\n"));
},
'test cross table output': function() {
var table = new Table({ head: ["", "Header 1", "Header 2"], style: {} }); // clear styles to prevent color output
table.push(
{"Header 3": ['v0.1', 'Testing something cool'] }
, {"Header 4": ['v0.1', 'Testing something cool'] }
);
var expected = [
'┌────────┬────────┬──────────────────────┐'
, '│ │Header 1│Header 2 │'
, '├────────┼────────┼──────────────────────┤'
, '│Header 3│v0.1 │Testing something cool│'
, '├────────┼────────┼──────────────────────┤'
, '│Header 4│v0.1 │Testing something cool│'
, '└────────┴────────┴──────────────────────┘'
];
table.toString().should.eql(expected.join("\n"));
}
};