From 64bbefd898b66b5c7d435f2da670116c28767127 Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Sat, 13 May 2017 11:34:14 +0300 Subject: [PATCH] test: Fix tests for 'TelegramBot#onText()' Bug: The registered listeners remain in effect even after the suite is completed; allowing other suites to trigger the listeners. Fix: Perform clean-up before moving to next suite. --- test/telegram.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/telegram.js b/test/telegram.js index 6b2e852..3602753 100644 --- a/test/telegram.js +++ b/test/telegram.js @@ -967,8 +967,10 @@ describe('TelegramBot', function telegramSuite() { describe('#onText', function onTextSuite() { it('should call `onText` callback on match', function test(done) { - botWebHook.onText(/\/onText (.+)/, (msg, match) => { + const regexp = /\/onText (.+)/; + botWebHook.onText(regexp, (msg, match) => { assert.equal(match[1], 'ECHO ALOHA'); + assert.ok(botWebHook.removeTextListener(regexp)); return done(); }); utils.sendWebHookMessage(webHookPort2, TOKEN, { @@ -979,6 +981,7 @@ describe('TelegramBot', function telegramSuite() { const regexp = /\/onText (.+)/g; botWebHook.onText(regexp, () => { assert.equal(regexp.lastIndex, 0); + assert.ok(botWebHook.removeTextListener(regexp)); return done(); }); utils.sendWebHookMessage(webHookPort2, TOKEN, {