Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc-cloned / node_modules / @protobufjs / eventemitter / tests / index.js
diff --git a/legacy-libs/grpc-cloned/node_modules/@protobufjs/eventemitter/tests/index.js b/legacy-libs/grpc-cloned/node_modules/@protobufjs/eventemitter/tests/index.js
new file mode 100644 (file)
index 0000000..aeee277
--- /dev/null
@@ -0,0 +1,47 @@
+var tape = require("tape");\r
+\r
+var EventEmitter = require("..");\r
+\r
+tape.test("eventemitter", function(test) {\r
+\r
+    var ee = new EventEmitter();\r
+    var fn;\r
+    var ctx = {};\r
+\r
+    test.doesNotThrow(function() {\r
+        ee.emit("a", 1);\r
+        ee.off();\r
+        ee.off("a");\r
+        ee.off("a", function() {});\r
+    }, "should not throw if no listeners are registered");\r
+    \r
+    test.equal(ee.on("a", function(arg1) {\r
+        test.equal(this, ctx, "should be called with this = ctx");\r
+        test.equal(arg1, 1, "should be called with arg1 = 1");\r
+    }, ctx), ee, "should return itself when registering events");\r
+    ee.emit("a", 1);\r
+\r
+    ee.off("a");\r
+    test.same(ee._listeners, { a: [] }, "should remove all listeners of the respective event when calling off(evt)");\r
+\r
+    ee.off();\r
+    test.same(ee._listeners, {}, "should remove all listeners when just calling off()");\r
+\r
+    ee.on("a", fn = function(arg1) {\r
+        test.equal(this, ctx, "should be called with this = ctx");\r
+        test.equal(arg1, 1, "should be called with arg1 = 1");\r
+    }, ctx).emit("a", 1);\r
+\r
+    ee.off("a", fn);\r
+    test.same(ee._listeners, { a: [] }, "should remove the exact listener when calling off(evt, fn)");\r
+\r
+    ee.on("a", function() {\r
+        test.equal(this, ee, "should be called with this = ee");\r
+    }).emit("a");\r
+\r
+    test.doesNotThrow(function() {\r
+        ee.off("a", fn);\r
+    }, "should not throw if no such listener is found");\r
+\r
+    test.end();\r
+});\r