Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / @protobufjs / eventemitter / tests / index.js
1 var tape = require("tape");\r
2 \r
3 var EventEmitter = require("..");\r
4 \r
5 tape.test("eventemitter", function(test) {\r
6 \r
7     var ee = new EventEmitter();\r
8     var fn;\r
9     var ctx = {};\r
10 \r
11     test.doesNotThrow(function() {\r
12         ee.emit("a", 1);\r
13         ee.off();\r
14         ee.off("a");\r
15         ee.off("a", function() {});\r
16     }, "should not throw if no listeners are registered");\r
17     \r
18     test.equal(ee.on("a", function(arg1) {\r
19         test.equal(this, ctx, "should be called with this = ctx");\r
20         test.equal(arg1, 1, "should be called with arg1 = 1");\r
21     }, ctx), ee, "should return itself when registering events");\r
22     ee.emit("a", 1);\r
23 \r
24     ee.off("a");\r
25     test.same(ee._listeners, { a: [] }, "should remove all listeners of the respective event when calling off(evt)");\r
26 \r
27     ee.off();\r
28     test.same(ee._listeners, {}, "should remove all listeners when just calling off()");\r
29 \r
30     ee.on("a", fn = function(arg1) {\r
31         test.equal(this, ctx, "should be called with this = ctx");\r
32         test.equal(arg1, 1, "should be called with arg1 = 1");\r
33     }, ctx).emit("a", 1);\r
34 \r
35     ee.off("a", fn);\r
36     test.same(ee._listeners, { a: [] }, "should remove the exact listener when calling off(evt, fn)");\r
37 \r
38     ee.on("a", function() {\r
39         test.equal(this, ee, "should be called with this = ee");\r
40     }).emit("a");\r
41 \r
42     test.doesNotThrow(function() {\r
43         ee.off("a", fn);\r
44     }, "should not throw if no such listener is found");\r
45 \r
46     test.end();\r
47 });\r