1 var tape = require("tape");
\r
3 var EventEmitter = require("..");
\r
5 tape.test("eventemitter", function(test) {
\r
7 var ee = new EventEmitter();
\r
11 test.doesNotThrow(function() {
\r
15 ee.off("a", function() {});
\r
16 }, "should not throw if no listeners are registered");
\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
25 test.same(ee._listeners, { a: [] }, "should remove all listeners of the respective event when calling off(evt)");
\r
28 test.same(ee._listeners, {}, "should remove all listeners when just calling off()");
\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
36 test.same(ee._listeners, { a: [] }, "should remove the exact listener when calling off(evt, fn)");
\r
38 ee.on("a", function() {
\r
39 test.equal(this, ee, "should be called with this = ee");
\r
42 test.doesNotThrow(function() {
\r
44 }, "should not throw if no such listener is found");
\r