This repository was archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathpassthrough-emitter.js
More file actions
62 lines (48 loc) · 1.84 KB
/
passthrough-emitter.js
File metadata and controls
62 lines (48 loc) · 1.84 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
'use strict';
const PassthroughEmitter = require('lib/passthrough-emitter');
describe('PassthroughEmitter', () => {
let runner,
child;
beforeEach(function() {
runner = new PassthroughEmitter();
child = new PassthroughEmitter();
});
it('should emit event emitted by child', () => {
let onSomeEvent = sinon.spy();
runner.on('some-event', onSomeEvent);
runner.passthroughEvent(child, 'some-event');
child.emit('some-event', 'some-data');
assert.calledWith(onSomeEvent, 'some-data');
});
it('should emit all events emitted by child', () => {
let onSomeEvent = sinon.spy(),
onOtherEvent = sinon.spy();
runner.on('some-event', onSomeEvent);
runner.on('other-event', onOtherEvent);
runner.passthroughEvent(child, ['some-event', 'other-event']);
child.emit('some-event', 'some-data');
child.emit('other-event', 'other-data');
assert.calledWith(onSomeEvent, 'some-data');
assert.calledWith(onOtherEvent, 'other-data');
});
it('should not break promise chain on event emitted by emitAndWait', () => {
runner.passthroughEvent(child, 'some-event');
runner.on('some-event', function() {
return 'some-data';
});
return child.emitAndWait('some-event')
.then((data) => {
assert.equal(data, 'some-data');
});
});
it('should be able to pass multiple event arguments', () => {
runner.passthroughEvent(child, 'some-event');
runner.on('some-event', function(...args) {
return `some-data ${args[0]} ${args[1]}`;
});
return child.emitAndWait('some-event', 'foo', 'bar')
.then((data) => {
assert.equal(data, `some-data foo bar`);
});
});
});