-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
50 lines (37 loc) · 1.31 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
const test = require('tape');
const makeMockCallbag = require('callbag-mock');
const trace = require('./index');
test('it calls func on values and then passes them down', t => {
let history = [];
let logger = []
const report = (name,dir,t,d) => t !== 0 && d !== undefined && history.push([name,dir,t,d]);
const source = makeMockCallbag('source', true);
const traceLog = trace(d => logger.push(d));
const sink = makeMockCallbag('sink', report);
traceLog(source)(0, sink);
source.emit(1, 'bar');
source.emit(1, 'baz');
source.emit(2, 'error');
t.deepEqual(history, [
['sink', 'body', 1, 'bar'],
['sink', 'body', 1, 'baz'],
['sink', 'body', 2, 'error'],
], 'sink gets seed and subsequent data');
t.deepEqual(logger, ['bar', 'baz'], 'trace calls func on data as it passes');
t.end();
});
test('it passes requests back up', t => {
let history = [];
const report = (name,dir,t,d) => t !== 0 && history.push([name,dir,t,d]);
const source = makeMockCallbag('source', report, true);
const traceLog = trace(console.log);
const sink = makeMockCallbag('sink', report);
traceLog(source)(0, sink);
sink.emit(1);
sink.emit(2);
t.deepEqual(history, [
['source', 'talkback', 1, undefined],
['source', 'talkback', 2, undefined],
], 'source gets requests from sink');
t.end();
});