From 761a82bc9a35f6bac1308115eca1961ffcaec1d8 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 16 Mar 2012 00:25:41 +0100 Subject: [PATCH] test: make .removeAllListeners() test more exhaustive Also test removal of multiple listeners, it's a separate code path. --- .../test-event-emitter-remove-all-listeners.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/simple/test-event-emitter-remove-all-listeners.js b/test/simple/test-event-emitter-remove-all-listeners.js index 39e6468c976..6e27f3eb702 100644 --- a/test/simple/test-event-emitter-remove-all-listeners.js +++ b/test/simple/test-event-emitter-remove-all-listeners.js @@ -29,14 +29,20 @@ function listener() {} var e1 = new events.EventEmitter(); e1.on('foo', listener); e1.on('bar', listener); +e1.on('baz', listener); +e1.on('baz', listener); var fooListeners = e1.listeners('foo'); var barListeners = e1.listeners('bar'); -e1.removeAllListeners('foo'); -assert.deepEqual(e1.listeners('foo'), []); -assert.deepEqual(e1.listeners('bar'), [listener]); +var bazListeners = e1.listeners('baz'); +e1.removeAllListeners('bar'); +e1.removeAllListeners('baz'); +assert.deepEqual(e1.listeners('foo'), [listener]); +assert.deepEqual(e1.listeners('bar'), []); +assert.deepEqual(e1.listeners('baz'), []); // identity check, the array should not change assert.equal(e1.listeners('foo'), fooListeners); assert.equal(e1.listeners('bar'), barListeners); +assert.equal(e1.listeners('baz'), bazListeners); var e2 = new events.EventEmitter(); e2.on('foo', listener);