{"id":17347176,"url":"https://github.com/ianmitchell/jest-discord","last_synced_at":"2025-04-14T20:43:41.038Z","repository":{"id":57280293,"uuid":"145483698","full_name":"IanMitchell/jest-discord","owner":"IanMitchell","description":"Jest Integrations for Discord.js","archived":false,"fork":false,"pushed_at":"2021-01-25T19:14:51.000Z","size":107,"stargazers_count":12,"open_issues_count":2,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-03T06:42:08.525Z","etag":null,"topics":["discord","discord-bot","jest","testing"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IanMitchell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-21T00:14:04.000Z","updated_at":"2024-02-03T06:59:15.000Z","dependencies_parsed_at":"2022-09-19T17:01:59.284Z","dependency_job_id":null,"html_url":"https://github.com/IanMitchell/jest-discord","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IanMitchell%2Fjest-discord","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IanMitchell%2Fjest-discord/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IanMitchell%2Fjest-discord/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IanMitchell%2Fjest-discord/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IanMitchell","download_url":"https://codeload.github.com/IanMitchell/jest-discord/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248960157,"owners_count":21189979,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discord","discord-bot","jest","testing"],"created_at":"2024-10-15T16:47:51.881Z","updated_at":"2025-04-14T20:43:41.020Z","avatar_url":"https://github.com/IanMitchell.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jest-discord\n\nA work in progress Jest plugin to work with [discord.js](https://discord.js.org/). This will spin up a test bot that you can use to send test messages to a server and react to your bot's responses. In practice, it may look something like this:\n\n![Example Playback](./example.png)\n\n```javascript\ndescribe('Ping', () =\u003e {\n  test('response', async () =\u003e {\n    const response = await prompt('ping');\n    expect(response).toBeMessage('pong');\n  });\n});\n```\n\n## Usage\n\n**This section is subject to extreme changes while the packages are developed and finalized!**\n\n_There are two packages that are part of this system - `packages/jest-discord` includes the matcher and the logic for the test bot, and `packages/jest-environment-discord` includes the code to create a custom Jest environment._\n\n\n## Discord\n\nYou'll first need to create a Bot and Guild on Discord in order to use this project. The test bot will need admin permissions on the guild. You should then add the bot you'd like to test.\n\nWhen running your tests, you'll need to have your bot running in a separate process.\n\nThe test bot will automatically create a unique test channel to run your tests in, and delete the channel when the test suite is finished.\n\n## Code\n\n```\n$ npm install jest-discord jest-environment-discord --save-dev\n```\n\nOr\n\n```\n$ yarn add jest-discord jest-environment-discord --dev\n```\n\nYou'll then need to tell Jest to use the Discord Environment - in your `jest.config.json` file, add the following parameters:\n\n```json\n{\n  \"testEnvironment\": \"jest-environment-discord\",\n  \"testEnvironmentOptions\": {\n    \"testGuildId\": \"\u003cGUILD_ID\u003e\"\n  },\n  \"globalSetup\": \"./test.global.js\",\n  \"setupTestFrameworkScriptFile\": \"./test.js\",\n  \"roots\": [\n    \"src/\"\n  ]\n}\n\n```\n\n_Replace `\u003cGUILD_ID\u003e` with the ID of your test guild_\n\nThis tells Jest to load up the `jest-environment-discord` package for each test file, and tells the environment what Discord Guild to use as a test guild.\n\nYour `./test.js` file should import the custom matchers:\n\n```javascript\nrequire('jest-discord/expect');\n```\n\nAnd your `./test.global.js` should set your environmental variables.\n\n **jest-discord expects a `process.env.TEST_BOT_TOKEN` variable!** The token provided will be used to control the test bot. Without one, the test suite cannot run.\n\n## API\n\n### Test Bot\n\n###### async prompt(str) =\u003e Discord.Message\n\nSends a message to a dedicated test channel. Returns a discord.js Message object that contains your bot's response. Will timeout and fail after 6 seconds.\n\n### Matchers\n\n###### toBeMessage(str)\n\nChecks to see if the received message matches the given string exactly (uses `.cleanContent` from `discord.js`)\n\n###### toHaveEmbed\n\nChecks to see if the message has one or more embeds\n\n# TODO\n\n- [ ] Installation / Usage\n- [ ] Documentation\n- [ ] Simple Examples\n- [ ] Figure out how to have multiple connections\n- [ ] Figure out how to spawn a test instance of the real bot\n- [ ] Additional Matchers\n- [ ] Write Package READMEs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fianmitchell%2Fjest-discord","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fianmitchell%2Fjest-discord","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fianmitchell%2Fjest-discord/lists"}