-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
45 lines (32 loc) · 927 Bytes
/
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
import test from 'ava';
import Events from './index.js';
test('Can listen to events', (t) => {
const eventManager = new Events();
let eventInput = null;
eventManager.on('test', (input) => {
eventInput = input;
});
eventManager.emit('test', 'foo');
t.is(eventInput, 'foo');
});
test('Can unsubscribe listeners', (t) => {
const eventManager = new Events();
let eventInput = null;
const cb = (input) => {
eventInput = input;
};
eventManager.on('test', cb);
eventManager.off('test', cb);
eventManager.emit('test', 'foo');
t.is(eventInput, null);
});
test('Can unsubscribe all listeners', (t) => {
const eventManager = new Events();
let eventInput = null;
eventManager.on('test', (input) => {
eventInput = input;
});
eventManager.removeAll('test');
eventManager.emit('test', 'foo');
t.is(eventInput, null);
});