-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathtest.emitter.js
44 lines (36 loc) · 971 Bytes
/
test.emitter.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
var ss = require('..')
, should = require('should');
var pub = ss.socket('pub-emitter')
, sub = ss.socket('sub-emitter');
// test basic 1-1 pub/sub emitter style
pub.bind(4000, function(){
sub.connect(4000, function(){
sub.on('foo', function(){
arguments.length.should.equal(0);
});
sub.on('bar', function(a, b, c){
arguments.length.should.equal(3);
a.should.equal(1);
b.should.equal(2);
c.should.equal(3);
});
sub.on('hai', function(a, b, c){
arguments.length.should.equal(3);
a.should.equal(4);
b.should.equal(5);
c.should.equal(6);
});
sub.on('baz', function(a){
arguments.length.should.equal(1);
a.should.have.property('name', 'tobi');
pub.close();
sub.close();
});
setTimeout(function(){
pub.emit('foo');
pub.emit('bar', 1, 2, 3);
pub.emit('hai', 4, 5, 6);
pub.emit('baz', { name: 'tobi' });
}, 20);
});
});