mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.4 KiB
57 lines
1.4 KiB
14 years ago
|
var common = require('../common');
|
||
|
var assert = require('assert');
|
||
15 years ago
|
var events = require('events');
|
||
|
|
||
14 years ago
|
var callbacks_called = [];
|
||
15 years ago
|
|
||
|
var e = new events.EventEmitter();
|
||
|
|
||
|
function callback1() {
|
||
14 years ago
|
callbacks_called.push('callback1');
|
||
13 years ago
|
e.on('foo', callback2);
|
||
|
e.on('foo', callback3);
|
||
14 years ago
|
e.removeListener('foo', callback1);
|
||
15 years ago
|
}
|
||
|
|
||
|
function callback2() {
|
||
14 years ago
|
callbacks_called.push('callback2');
|
||
|
e.removeListener('foo', callback2);
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
function callback3() {
|
||
14 years ago
|
callbacks_called.push('callback3');
|
||
|
e.removeListener('foo', callback3);
|
||
15 years ago
|
}
|
||
|
|
||
13 years ago
|
e.on('foo', callback1);
|
||
14 years ago
|
assert.equal(1, e.listeners('foo').length);
|
||
15 years ago
|
|
||
14 years ago
|
e.emit('foo');
|
||
|
assert.equal(2, e.listeners('foo').length);
|
||
|
assert.deepEqual(['callback1'], callbacks_called);
|
||
15 years ago
|
|
||
14 years ago
|
e.emit('foo');
|
||
|
assert.equal(0, e.listeners('foo').length);
|
||
|
assert.deepEqual(['callback1', 'callback2', 'callback3'], callbacks_called);
|
||
15 years ago
|
|
||
14 years ago
|
e.emit('foo');
|
||
|
assert.equal(0, e.listeners('foo').length);
|
||
|
assert.deepEqual(['callback1', 'callback2', 'callback3'], callbacks_called);
|
||
15 years ago
|
|
||
13 years ago
|
e.on('foo', callback1);
|
||
|
e.on('foo', callback2);
|
||
14 years ago
|
assert.equal(2, e.listeners('foo').length);
|
||
|
e.removeAllListeners('foo');
|
||
|
assert.equal(0, e.listeners('foo').length);
|
||
15 years ago
|
|
||
15 years ago
|
// Verify that removing callbacks while in emit allows emits to propagate to
|
||
15 years ago
|
// all listeners
|
||
14 years ago
|
callbacks_called = [];
|
||
|
|
||
13 years ago
|
e.on('foo', callback2);
|
||
|
e.on('foo', callback3);
|
||
14 years ago
|
assert.equal(2, e.listeners('foo').length);
|
||
|
e.emit('foo');
|
||
|
assert.deepEqual(['callback2', 'callback3'], callbacks_called);
|
||
|
assert.equal(0, e.listeners('foo').length);
|