Skip to content

Commit

Permalink
fix error listener handler case
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Feb 27, 2021
1 parent f1d67b0 commit 133faed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion events.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,9 @@ function once(emitter, name) {
};

eventTargetAgnosticAddListener(emitter, name, resolver, { once: true });
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
if (name !== 'error') {
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
}
});
}

Expand Down
4 changes: 3 additions & 1 deletion tests/events-once.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ function onceError() {
ee.emit('error', expected);
});

return once(ee, 'error').then(function (args) {
var promise = once(ee, 'error');
assert.strictEqual(ee.listenerCount('error'), 1);
return promise.then(function (args) {
var err = args[0]
assert.strictEqual(err, expected);
assert.strictEqual(ee.listenerCount('error'), 0);
Expand Down

0 comments on commit 133faed

Please sign in to comment.