-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
58 lines (43 loc) · 1.27 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
describe('eventstub', function () {
'use strict';
var EventEmitter = require('eventemitter3')
, assume = require('assume')
, stub = require('./');
it('is exported as fn', function () {
assume(stub).is.a('function');
});
it('returns an EventEmitter', function () {
var e = stub();
assume(e).is.instanceOf(EventEmitter);
});
it('it adds the supplied methods', function () {
var e = stub(['message', 'cows', 'moo']);
assume(e).has.property('onmessage');
assume(e).has.property('oncows');
assume(e).has.property('onmoo');
assume(e.listeners('cows').length).equals(0);
/* istanbul ignore next */
e.oncows = function () {};
assume(e.oncows).is.a('function');
assume(e.listeners('cows').length).equals(1);
});
it('it adds the supplied fn as eventemitter', function (next) {
var e = stub(['foo']);
function foo(arg) {
assume(arg).equals('bar');
assume(e.onfoo).equals(foo);
next();
}
e.onfoo = foo;
e.emit('foo', 'bar');
});
it('removes the previously added event listener', function (next) {
var e = stub('foo');
/* istanbul ignore next */
e.onfoo = function () {
throw new Error('I should be removed');
};
e.onfoo = next;
e.emit('foo');
});
});