-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
64 lines (48 loc) · 1.3 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
/* jshint node:true */
/* globals describe, it */
'use strict';
var chai = require('chai');
var expect = chai.expect;
var events = require(__dirname);
describe('#redis-events', function() {
it('should work for one event', function(done) {
var emitter = new events.EventEmitter();
var seen = 0;
emitter.on('msg', function(lvl, msg) {
seen += 1;
expect(['info', 'error']).to.contain(lvl);
if (seen === 2) {
done();
}
});
emitter.subscriber.on('subscribe', function() {
emitter.emit('msg', 'info', 'this is an informational message');
emitter.emit('msg', 'error', 'this is an error message');
});
});
// issue - https://github.com/jksdua/redis-events/issues/2
it('should work for multiple events', function(done) {
var emitter = new events.EventEmitter();
var seen = 0;
emitter.on('bla.msg', function(arg1, arg2) {
seen += 1;
expect(arg1).to.equal('bla1');
expect(arg2).to.equal(1);
if (seen === 2) {
done();
}
});
emitter.on('foo.msg', function(arg1, arg2) {
seen += 1;
expect(arg1).to.eql({ foo: 'baz' });
expect(arg2).to.equal(2);
if (seen === 2) {
done();
}
});
emitter.emit('bla.msg', 'bla1', 1);
emitter.emit('foo.msg', { foo: 'baz' }, 2);
});
it('should only call listener once for local event', function() {
});
});