Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/PavelPolyakov/grammy-with-tests
https://github.com/PavelPolyakov/grammy-with-tests
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/PavelPolyakov/grammy-with-tests
- Owner: PavelPolyakov
- Created: 2022-02-18T14:33:04.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-02-18T15:17:30.000Z (over 2 years ago)
- Last Synced: 2024-07-15T10:48:25.830Z (4 months ago)
- Language: JavaScript
- Size: 71.3 KB
- Stars: 15
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-grammY - PavelPolyakov/grammy-with-tests - An example bot which is covered with tests. (Templates)
README
# grammY with tests
This repository's purpose is to demonstrate how Telegram bots, developed with the help of [grammY](https://grammy.dev/) framework could be tested.
## Explanation
It's assumed, that you configure complete bot logic in the [bot.js](bot.js) file end then export it.
So your bot can be imported in the [\_\_tests\_\_/bot.test.js](__tests__/bot.test.js) and tested.During the tests we do not want our bot to interact with Telegram servers in any way. We can use [transformer function](https://grammy.dev/advanced/transformers.html#installing-a-transformer-function) which catches the outgoing requests. In our [example](__tests__/bot.test.js#L29), we record these outgoing requests, so later we can [assert](__tests__/bot.test.js#L58) them.
## How to run it
```sh
npm i
# run tests
npm test
# run bot
BOT_TOKEN=%YOUR_TOKEN% node start.js
```