0.1.6 • Published 4 years ago

telegrafer v0.1.6

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Telegrafer

About

Telegrafer is a high-level abstraction for testing Telegraf based applications.

Installation

Using npm:

npm install --save-dev telegrafer

Using yarn:

yarn add --dev telegrafer

Example

Telegrafer is a test framework agnostic, here is an example without using any test framework at all:

import Telegraf from 'telegraf';
import { update } from 'telegrafer';

const bot = new Telegraf('test:token');

bot.start((ctx) => {
  ctx.reply('start');
});

update(bot)
  .command('start')
  .reply()
  .method('sendMessage')
  .data({ chat_id: 0, text: 'start' })
  .end();

Here's an example with jest, note you must pass done to the .end call:

it(`should handle "one" action`, (done) => {
  const buttonOne = Markup.callbackButton('One Button', 'one');

  bot.action(buttonOne.callback_data, (ctx) => {
    return ctx.reply('Two!');
  });

  update(bot)
    .action(buttonOne.callback_data)
    .reply()
    .method('sendMessage')
    .data({ chat_id: 0, text: 'Two!' })
    .end(done);
});

Documentation

Please see the documentation for all supported methods

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago