forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffered_console.test.js
More file actions
134 lines (108 loc) · 3.28 KB
/
buffered_console.test.js
File metadata and controls
134 lines (108 loc) · 3.28 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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import chalk from 'chalk';
import BufferedConsole from '../buffered_console';
describe('CustomConsole', () => {
let _console;
const stdout = () =>
_console
.getBuffer()
.map(log => log.message)
.join('\n');
beforeEach(() => {
_console = new BufferedConsole();
});
describe('assert', () => {
test('log when the assertion is truthy', () => {
_console.assert(true, 'ok');
expect(stdout()).toMatch('ok');
});
test('do not log when the assertion is falsy', () => {
_console.assert(false, 'ok');
expect(stdout()).toEqual('');
});
});
describe('count', () => {
test('count using the default counter', () => {
_console.count();
_console.count();
_console.count();
expect(stdout()).toEqual('default: 1\ndefault: 2\ndefault: 3');
});
test('count using the a labeled counter', () => {
_console.count('custom');
_console.count('custom');
_console.count('custom');
expect(stdout()).toEqual('custom: 1\ncustom: 2\ncustom: 3');
});
test('countReset restarts default counter', () => {
_console.count();
_console.count();
_console.countReset();
_console.count();
expect(stdout()).toEqual('default: 1\ndefault: 2\ndefault: 1');
});
test('countReset restarts custom counter', () => {
_console.count('custom');
_console.count('custom');
_console.countReset('custom');
_console.count('custom');
expect(stdout()).toEqual('custom: 1\ncustom: 2\ncustom: 1');
});
});
describe('group', () => {
test('group without label', () => {
_console.group();
_console.log('hey');
_console.group();
_console.log('there');
expect(stdout()).toEqual(' hey\n there');
});
test('group with label', () => {
_console.group('first');
_console.log('hey');
_console.group('second');
_console.log('there');
expect(stdout()).toEqual(` ${chalk.bold('first')}
hey
${chalk.bold('second')}
there`);
});
test('groupEnd remove the indentation of the current group', () => {
_console.group();
_console.log('hey');
_console.groupEnd();
_console.log('there');
expect(stdout()).toEqual(' hey\nthere');
});
test('groupEnd can not remove the indentation below the starting point', () => {
_console.groupEnd();
_console.groupEnd();
_console.group();
_console.log('hey');
_console.groupEnd();
_console.log('there');
expect(stdout()).toEqual(' hey\nthere');
});
});
describe('time', () => {
test('should return the time between time() and timeEnd() on default timer', () => {
_console.time();
_console.timeEnd();
expect(stdout()).toMatch('default: ');
expect(stdout()).toMatch('ms');
});
test('should return the time between time() and timeEnd() on custom timer', () => {
_console.time('custom');
_console.timeEnd('custom');
expect(stdout()).toMatch('custom: ');
expect(stdout()).toMatch('ms');
});
});
});