Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jajbshjahavahh
GitHub Repository: jajbshjahavahh/Gojo-Satoru
Path: blob/master/node_modules/@protobufjs/eventemitter/tests/index.js
2593 views
1
var tape = require("tape");
2
3
var EventEmitter = require("..");
4
5
tape.test("eventemitter", function(test) {
6
7
var ee = new EventEmitter();
8
var fn;
9
var ctx = {};
10
11
test.doesNotThrow(function() {
12
ee.emit("a", 1);
13
ee.off();
14
ee.off("a");
15
ee.off("a", function() {});
16
}, "should not throw if no listeners are registered");
17
18
test.equal(ee.on("a", function(arg1) {
19
test.equal(this, ctx, "should be called with this = ctx");
20
test.equal(arg1, 1, "should be called with arg1 = 1");
21
}, ctx), ee, "should return itself when registering events");
22
ee.emit("a", 1);
23
24
ee.off("a");
25
test.same(ee._listeners, { a: [] }, "should remove all listeners of the respective event when calling off(evt)");
26
27
ee.off();
28
test.same(ee._listeners, {}, "should remove all listeners when just calling off()");
29
30
ee.on("a", fn = function(arg1) {
31
test.equal(this, ctx, "should be called with this = ctx");
32
test.equal(arg1, 1, "should be called with arg1 = 1");
33
}, ctx).emit("a", 1);
34
35
ee.off("a", fn);
36
test.same(ee._listeners, { a: [] }, "should remove the exact listener when calling off(evt, fn)");
37
38
ee.on("a", function() {
39
test.equal(this, ee, "should be called with this = ee");
40
}).emit("a");
41
42
test.doesNotThrow(function() {
43
ee.off("a", fn);
44
}, "should not throw if no such listener is found");
45
46
test.end();
47
});
48
49