-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest.js
70 lines (55 loc) · 1.5 KB
/
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
import test from 'ava';
import sinon from 'sinon';
import filterConsole from './index.js';
const methods = [
'log',
'debug',
'info',
'warn',
'error',
];
const getConsole = () => {
const customConsole = {};
for (const method of methods) {
customConsole[method] = sinon.fake();
}
return customConsole;
};
test('main', t => {
const customConsole = getConsole();
const fixture1 = '-1-';
const fixture2 = '-2-';
const fixture3 = '-3-';
const fixture4 = 'Foo Bar';
const fixture5 = 'unicorn';
const disableFilter = filterConsole([
'2',
/^foo/i,
output => output.endsWith('corn'),
], {console: customConsole});
customConsole.log(fixture1);
customConsole.log(fixture2);
customConsole.log(fixture3);
customConsole.log(fixture4);
customConsole.log(fixture5);
t.true(customConsole.log.original.calledWith(fixture1));
t.false(customConsole.log.original.calledWith(fixture2));
t.true(customConsole.log.original.calledWith(fixture3));
t.false(customConsole.log.original.calledWith(fixture4));
t.false(customConsole.log.original.calledWith(fixture5));
disableFilter();
customConsole.log(fixture2);
t.true(customConsole.log.calledWith(fixture2));
});
test('`methods` option`', t => {
const customConsole = getConsole();
const fixture1 = '1';
filterConsole([fixture1], {
console: customConsole,
methods: ['warn'],
});
customConsole.log(fixture1);
t.true(customConsole.log.calledWith(fixture1));
customConsole.warn(fixture1);
t.false(customConsole.warn.original.calledWith(fixture1));
});