2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-31 06:16:07 +00:00

src/telegram: Add TelegramBot#removeTextListener()

Feature:

  This is the opposite action to `TelegramBot#onText()`.
  It allows removing any previously-registered listeners.

  It is similar to `TelegramBot#removeReplyListener()`.
This commit is contained in:
GochoMugo
2017-05-13 11:28:04 +03:00
parent 9f3107b5ab
commit 11bcdd3b6a
3 changed files with 54 additions and 0 deletions

View File

@@ -987,6 +987,28 @@ describe('TelegramBot', function telegramSuite() {
});
});
describe('#removeTextListener', function removeTextListenerSuite() {
const regexp = /\/onText/;
const regexp2 = /\/onText/;
const callback = function noop() {};
after(function after() {
bot.removeTextListener(regexp);
bot.removeTextListener(regexp2);
});
it('removes the right text-listener', function test() {
bot.onText(regexp, callback);
bot.onText(regexp2, callback);
const textListener = bot.removeTextListener(regexp);
assert.equal(regexp, textListener.regexp);
assert.equal(callback, textListener.callback);
assert.notEqual(regexp2, textListener.regexp);
assert.equal(null, bot.removeTextListener(regexp));
});
it('returns `null` if missing', function test() {
assert.equal(null, bot.removeTextListener(/404/));
});
});
describe.skip('#onReplyToMessage', function onReplyToMessageSuite() {});
describe('#removeReplyListener', function removeReplyListenerSuite() {