Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: add missing type of removeEventListener in question #45676

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/readline.js
Expand Up @@ -145,7 +145,7 @@ Interface.prototype.question = function question(query, options, cb) {
};
options.signal.addEventListener('abort', onAbort, { once: true });
const cleanup = () => {
options.signal.removeEventListener(onAbort);
options.signal.removeEventListener('abort', onAbort);
};
const originalCb = cb;
cb = typeof cb === 'function' ? (answer) => {
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-readline-interface.js
Expand Up @@ -921,6 +921,24 @@ for (let i = 0; i < 12; i++) {
fi.emit('data', 'asdf\n');
}

// Ensure that options.signal.removeEventListener was called
{
const ac = new AbortController();
const signal = ac.signal;
const [rli] = getInterface({ terminal });
signal.removeEventListener = common.mustCall(
(event, onAbortFn) => {
assert.strictEqual(event, 'abort');
assert.strictEqual(onAbortFn.name, 'onAbort');
});

rli.question('hello?', { signal }, common.mustCall());

rli.write('bar\n');
ac.abort();
rli.close();
}

// Sending a blank line
{
const [rli, fi] = getInterface({ terminal });
Expand Down