Skip to content

Utility typescript exports of Jest Mocks for various discord.js classes to make testing easier

License

Notifications You must be signed in to change notification settings

Chris-Bitler/jest-discordjs-mocks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jest Discord.js Mocks

A bunch of mocks that can be used in place for various discord.js classes for unit testing with Jest.

Usage

You can import the Mock classes for the discord.js class that you are trying to mock out, such as MockMessage

From there, you can set various properties and replace methods with jest.fn() calls.

Example:

import {MockMessage, MockTextChannel} from "jest-discordjs-mocks";

test("discord.js mock test", () => {
    const message = new MockMessage();
    const channel = new MockTextChannel();
    message.content = "test";
    message.channel = channel;
    callMyFunctionToTestHere(message);
    expect(message.channel.send).toHaveBeenCalled()
});

Why some classes are exported and some aren't

Jest only allows for mocking certain classes from discord.js in typescript - the rest will result in errors

About

Utility typescript exports of Jest Mocks for various discord.js classes to make testing easier

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published