aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSakthipriyan Vairamani <thechargingvolcano@gmail.com>2015-08-12 00:01:50 +0530
committerSakthipriyan Vairamani <thechargingvolcano@gmail.com>2015-08-20 03:17:08 +0530
commit8f58fb92fff904a6ca58fd0df9ee5a1816e5b84e (patch)
treea3eb0aea4cfa4d7f3cbb85adefe60ca621901f89 /test
parentd98eed51f782ea44c3fd7823b2912f7fb30ab185 (diff)
downloadandroid-node-v8-8f58fb92fff904a6ca58fd0df9ee5a1816e5b84e.tar.gz
android-node-v8-8f58fb92fff904a6ca58fd0df9ee5a1816e5b84e.tar.bz2
android-node-v8-8f58fb92fff904a6ca58fd0df9ee5a1816e5b84e.zip
events: deprecate static listenerCount function
As per the discussion in #734, this patch deprecates the usage of `EventEmitter.listenerCount` static function in the docs, and introduces the `listenerCount` function in the prototype of `EventEmitter` itself. PR-URL: https://github.com/nodejs/node/pull/2349 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-event-emitter-listener-count.js18
-rw-r--r--test/parallel/test-event-emitter-subclass.js2
2 files changed, 19 insertions, 1 deletions
diff --git a/test/parallel/test-event-emitter-listener-count.js b/test/parallel/test-event-emitter-listener-count.js
new file mode 100644
index 0000000000..c5b75c819d
--- /dev/null
+++ b/test/parallel/test-event-emitter-listener-count.js
@@ -0,0 +1,18 @@
+'use strict';
+
+const common = require('../common');
+const assert = require('assert');
+const EventEmitter = require('events');
+
+const emitter = new EventEmitter();
+emitter.on('foo', function() {});
+emitter.on('foo', function() {});
+emitter.on('baz', function() {});
+// Allow any type
+emitter.on(123, function() {});
+
+assert.strictEqual(EventEmitter.listenerCount(emitter, 'foo'), 2);
+assert.strictEqual(emitter.listenerCount('foo'), 2);
+assert.strictEqual(emitter.listenerCount('bar'), 0);
+assert.strictEqual(emitter.listenerCount('baz'), 1);
+assert.strictEqual(emitter.listenerCount(123), 1);
diff --git a/test/parallel/test-event-emitter-subclass.js b/test/parallel/test-event-emitter-subclass.js
index 3277382711..fe915be34e 100644
--- a/test/parallel/test-event-emitter-subclass.js
+++ b/test/parallel/test-event-emitter-subclass.js
@@ -46,4 +46,4 @@ var ee2 = new MyEE2();
ee1.on('x', function() {});
-assert.equal(EventEmitter.listenerCount(ee2, 'x'), 0);
+assert.equal(ee2.listenerCount('x'), 0);