New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

discordjs-testing

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discordjs-testing

Helper package for testing DiscordJS bots with Mocha/Chai

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Discord.js Testing Lib

This is just a basic tool for mocking Discord.js classes for testing purposes.

Usage

Here's a basic example from one of our projects:

import { assert } from "chai";
import { ApplicationCommandOptionType, ChannelType } from "discord.js";
import {
  MockChannel,
  MockChatInputCommandInteraction,
  MockGuild,
  MockMember,
  MockUser,
  MockWebhook,
} from "discordjs-testing";

import { help } from "../../src/commands/help";

const guild = new MockGuild({
  name: "Test Guild",
});
const bot = new MockUser({
  username: "Test Bot",
  avatar: "test",
  discriminator: 1234,
  bot: true,
  system: false,
});
const user = new MockUser({
  username: "Test User",
  avatar: "test",
  discriminator: 1234,
  bot: false,
  system: false,
});
const member = new MockMember({
  guild,
  user,
});
const channel = new MockChannel({
  name: "test-channel",
  guild,
  type: ChannelType.GuildText,
});
const debugHook = new MockWebhook({
  channel,
  user: bot,
});

suite("Help command", () => {
  test("should respond correctly", async () => {
    const command = new MockChatInputCommandInteraction({
      commandName: "help",
      guild,
      bot,
      user,
      member,
      channel,
      options: [
        {
          name: "question",
          value: "How do I get Naomi to do work for me?",
          type: ApplicationCommandOptionType.String,
        },
      ],
    });
    await help.run({ ...bot, env: { debugHook } } as never, command.typeCast());
    assert.equal(command.replies.length, 1);
    assert.strictEqual(
      command.replies[0]?.content,
      "Greetings! I am Melody Iuvo, Naomi's personal assistant. My role here is to provide access to information you might need when finding your way around our community. Use my `/faq` command if you have a question!\n\nI want to ensure you have fun while you are here, so I also manage a few other facets of our group."
    );
  });
});

Note that while we use Mocha/Chai, this package should work with your favourite testing framework.

For the full API documentation, please see our documentation site.

Feedback and Bugs

If you have feedback or a bug report, please feel free to open a GitHub issue!

Contributing

If you would like to contribute to the project, you may create a Pull Request containing your proposed changes and we will review it as soon as we are able! Please review our contributing guidelines first.

Code of Conduct

Before interacting with our community, please read our Code of Conduct.

License

This software is licensed under our global software license.

Copyright held by Naomi Carrigan.

Contact

We may be contacted through our Chat Server or via email at contact@nhcarrigan.com.

Keywords

FAQs

Package last updated on 31 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc