Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
fix(event): fix #1021, removeListener/removeAllListeners should retur…
Browse files Browse the repository at this point in the history
…n eventEmitter (#1022)
  • Loading branch information
JiaLiPassion authored and mhevery committed Mar 14, 2018
1 parent eefe983 commit ab72df6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/common/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,9 @@ export function patchEventTarget(
target[symbolEventName] = null;
}
existingTask.zone.cancelTask(existingTask);
if (returnTarget) {
return target;
}
return;
}
}
Expand Down Expand Up @@ -571,6 +574,10 @@ export function patchEventTarget(
}
}
}

if (returnTarget) {
return this;
}
};

// for native toString patch
Expand Down
15 changes: 15 additions & 0 deletions test/node/events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ describe('nodejs EventEmitter', () => {
emitter.emit('test2', 'test value');
});
});
it('remove listener should return event emitter', () => {
zoneA.run(() => {
emitter.on('test', shouldNotRun);
expect(emitter.removeListener('test', shouldNotRun)).toEqual(emitter);
emitter.emit('test', 'test value');
});
});
it('should return all listeners for an event', () => {
zoneA.run(() => {
emitter.on('test', expectZoneA);
Expand Down Expand Up @@ -106,6 +113,14 @@ describe('nodejs EventEmitter', () => {
expect(emitter.listeners('test').length).toEqual(0);
});
});
it('remove All listeners should return event emitter', () => {
zoneA.run(() => {
emitter.on('test', expectZoneA);
emitter.on('test', expectZoneA);
expect(emitter.removeAllListeners('test')).toEqual(emitter);
expect(emitter.listeners('test').length).toEqual(0);
});
});
it('should remove All listeners properly even without a type parameter', () => {
zoneA.run(() => {
emitter.on('test', shouldNotRun);
Expand Down

0 comments on commit ab72df6

Please sign in to comment.