react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / events / tests / remove-listeners.js
80727 views// Copyright Joyent, Inc. and other Node contributors.1//2// Permission is hereby granted, free of charge, to any person obtaining a3// copy of this software and associated documentation files (the4// "Software"), to deal in the Software without restriction, including5// without limitation the rights to use, copy, modify, merge, publish,6// distribute, sublicense, and/or sell copies of the Software, and to permit7// persons to whom the Software is furnished to do so, subject to the8// following conditions:9//10// The above copyright notice and this permission notice shall be included11// in all copies or substantial portions of the Software.12//13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS14// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF15// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN16// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,17// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR18// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE19// USE OR OTHER DEALINGS IN THE SOFTWARE.2021var common = require('./common');22var assert = require('assert');23var events = require('../');2425var count = 0;2627function listener1() {28console.log('listener1');29count++;30}3132function listener2() {33console.log('listener2');34count++;35}3637function listener3() {38console.log('listener3');39count++;40}4142function remove1() {43assert(0);44}4546function remove2() {47assert(0);48}4950var e1 = new events.EventEmitter();51e1.on('hello', listener1);52e1.on('removeListener', common.mustCall(function(name, cb) {53assert.equal(name, 'hello');54assert.equal(cb, listener1);55}));56e1.removeListener('hello', listener1);57assert.deepEqual([], e1.listeners('hello'));5859var e2 = new events.EventEmitter();60e2.on('hello', listener1);61e2.on('removeListener', assert.fail);62e2.removeListener('hello', listener2);63assert.deepEqual([listener1], e2.listeners('hello'));6465var e3 = new events.EventEmitter();66e3.on('hello', listener1);67e3.on('hello', listener2);68e3.on('removeListener', common.mustCall(function(name, cb) {69assert.equal(name, 'hello');70assert.equal(cb, listener1);71}));72e3.removeListener('hello', listener1);73assert.deepEqual([listener2], e3.listeners('hello'));7475var e4 = new events.EventEmitter();76e4.on('removeListener', common.mustCall(function(name, cb) {77if (cb !== remove1) return;78this.removeListener('quux', remove2);79this.emit('quux');80}, 2));81e4.on('quux', remove1);82e4.on('quux', remove2);83e4.removeListener('quux', remove1);848586