2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-29 13:27:44 +00:00

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.
This commit is contained in:
GochoMugo 2017-05-13 11:34:14 +03:00
parent 11bcdd3b6a
commit 64bbefd898
No known key found for this signature in database
GPG Key ID: 7B6A01CB57AA39E4

View File

@ -967,8 +967,10 @@ describe('TelegramBot', function telegramSuite() {
describe('#onText', function onTextSuite() { describe('#onText', function onTextSuite() {
it('should call `onText` callback on match', function test(done) { 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.equal(match[1], 'ECHO ALOHA');
assert.ok(botWebHook.removeTextListener(regexp));
return done(); return done();
}); });
utils.sendWebHookMessage(webHookPort2, TOKEN, { utils.sendWebHookMessage(webHookPort2, TOKEN, {
@ -979,6 +981,7 @@ describe('TelegramBot', function telegramSuite() {
const regexp = /\/onText (.+)/g; const regexp = /\/onText (.+)/g;
botWebHook.onText(regexp, () => { botWebHook.onText(regexp, () => {
assert.equal(regexp.lastIndex, 0); assert.equal(regexp.lastIndex, 0);
assert.ok(botWebHook.removeTextListener(regexp));
return done(); return done();
}); });
utils.sendWebHookMessage(webHookPort2, TOKEN, { utils.sendWebHookMessage(webHookPort2, TOKEN, {