Path: blob/master/node_modules/@protobufjs/eventemitter/tests/index.js
2593 views
var tape = require("tape");12var EventEmitter = require("..");34tape.test("eventemitter", function(test) {56var ee = new EventEmitter();7var fn;8var ctx = {};910test.doesNotThrow(function() {11ee.emit("a", 1);12ee.off();13ee.off("a");14ee.off("a", function() {});15}, "should not throw if no listeners are registered");1617test.equal(ee.on("a", function(arg1) {18test.equal(this, ctx, "should be called with this = ctx");19test.equal(arg1, 1, "should be called with arg1 = 1");20}, ctx), ee, "should return itself when registering events");21ee.emit("a", 1);2223ee.off("a");24test.same(ee._listeners, { a: [] }, "should remove all listeners of the respective event when calling off(evt)");2526ee.off();27test.same(ee._listeners, {}, "should remove all listeners when just calling off()");2829ee.on("a", fn = function(arg1) {30test.equal(this, ctx, "should be called with this = ctx");31test.equal(arg1, 1, "should be called with arg1 = 1");32}, ctx).emit("a", 1);3334ee.off("a", fn);35test.same(ee._listeners, { a: [] }, "should remove the exact listener when calling off(evt, fn)");3637ee.on("a", function() {38test.equal(this, ee, "should be called with this = ee");39}).emit("a");4041test.doesNotThrow(function() {42ee.off("a", fn);43}, "should not throw if no such listener is found");4445test.end();46});474849