{"_id":"@beanieman/discordjs-mock","name":"@beanieman/discordjs-mock","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.3":{"name":"@beanieman/discordjs-mock","version":"1.0.3","main":"./dist/index.js","types":"./dist/index.d.ts","type":"module","author":{"name":"@beanieman"},"license":"MIT","private":false,"publishConfig":{"access":"public"},"exports":{".":{"import":"./dist/index.js","require":"./dist/index.cjs","types":"./dist/index.d.ts"},"./package.json":{"import":"./package.json","require":"./package.json"}},"devDependencies":{"@tsconfig/strictest":"^2.0.5","@types/lodash":"^4.17.0","@types/node":"^20.11.30","@typescript-eslint/eslint-plugin":"^7.4.0","eslint":"^8.57.0","eslint-config-prettier":"^9.1.0","eslint-plugin-deprecation":"^2.0.0","eslint-plugin-import":"^2.29.1","eslint-plugin-jsdoc":"^48.2.2","eslint-plugin-simple-import-sort":"^12.0.0","eslint-plugin-unicorn":"^51.0.1","prettier":"^3.2.5","ts-node":"^10.9.2","tsup":"^8.0.2","typescript":"^5.4.3"},"scripts":{"prepublishOnly":"yarn build","build":"tsup index.ts --target node18 --format cjs,esm --dts --sourcemap","build-watch":"yarn build -- --watch","clean":"rm -rf dist coverage","format":"prettier --ignore-path .gitignore --config .prettierrc.cjs --write ./src","format:check":"prettier --ignore-path .gitignore --config .prettierrc.cjs --check ./src","lint":"eslint ./src && tsc --noEmit","lint:fix":"eslint ./src --fix"},"peerDependencies":{"discord.js":"^14.13.0"},"dependencies":{"@sapphire/snowflake":"^3.5.3","discord.js":"^14.14.1","lodash":"^4.17.21","vitest":"^1.4.0"},"description":"This repository contains mocks for the [Discord.js](https://discord.js.org) library.","_id":"@beanieman/discordjs-mock@1.0.3","dist":{"shasum":"b3930dd52c613681053ac1997e3e887a47dba764","integrity":"sha512-IwrPXmPBMCaNwCICzZ5Ia8UHUH7zgR44UAD9wNtYC5aVxamzr1NFuQQ2ihPmui13Hl9lG7I6koWjmOd4PZJI7A==","tarball":"https://registry.npmjs.org/@beanieman/discordjs-mock/-/discordjs-mock-1.0.3.tgz","fileCount":13,"unpackedSize":228700,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCPX6wwQ0m5Y+GvYIo0BdGfXmrDky2MCpmg9yEhnYRABAIhAM36IHlwL5dX+RV7G/I5AMeG6mnaL1anYiW+hLredPaw"}]},"_npmUser":{"name":"beanieman","email":"jainarjav886@gmail.com"},"directories":{},"maintainers":[{"name":"beanieman","email":"jainarjav886@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/discordjs-mock_1.0.3_1711879965766_0.23585564179106244"},"_hasShrinkwrap":false}},"time":{"created":"2024-03-31T10:12:45.664Z","1.0.3":"2024-03-31T10:12:45.968Z","modified":"2024-03-31T10:12:46.287Z"},"maintainers":[{"name":"beanieman","email":"jainarjav886@gmail.com"}],"description":"This repository contains mocks for the [Discord.js](https://discord.js.org) library.","author":{"name":"@beanieman"},"license":"MIT","readme":"# Discord.js v14 Mocks\n\nThis repository contains mocks for the [Discord.js](https://discord.js.org) library.\n\nI created this repository because I wanted to write tests for my Discord bots, but I didn't want to use the real Discord.js library. I wanted to use a mock library that would allow me to test my code without having to worry about the Discord API. I also wanted to be able to test my code without having to worry about the Discord API.\n\nI found a repository that had this as a good base but I wanted more control over the dependencies and the mocks. So I created this repository.\n\nThe source was: [AnswerOverflow](https://github.com/AnswerOverflow/AnswerOverflow) and their [Discord.js Mocks](https://github.com/AnswerOverflow/AnswerOverflow/tree/main/packages/discordjs-mock)\n\n## Example\n\nThe example below is using DiscordX and a simple singleton class to create the mocks. This is just an example and you can use any library you want to create the mocks.\n\n```ts\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { jest } from '@jest/globals';\nimport {\n  mockClientUser,\n  mockGuild,\n  mockGuildMember,\n  mockTextChannel,\n  mockUser,\n} from '@shoginn/discordjs-mock';\nimport { Client, Guild, TextBasedChannel, TextChannel, User } from 'discord.js';\nimport { Client as ClientX } from 'discordx';\nimport { singleton } from 'tsyringe';\n\n@singleton()\nexport class Mock {\n  private client!: Client;\n  private guild!: Guild;\n  private channel!: TextChannel;\n  private user!: User;\n\n  getClient(withBots: boolean = false): Client {\n    if (withBots) {\n      const botUser = mockUser(this.client, { bot: true });\n      mockGuildMember({\n        client: this.client,\n        user: botUser,\n        guild: this.guild,\n      });\n    }\n    return this.client;\n  }\n  getUser(): User {\n    return this.user;\n  }\n  getGuild(): Guild {\n    return this.guild;\n  }\n  getChannel(): TextBasedChannel {\n    return this.channel;\n  }\n  constructor() {\n    this.mockClient();\n    this.mockGuild();\n    this.mockUser();\n    this.mockChannel();\n  }\n\n  private mockClient(): void {\n    this.client = new ClientX({ intents: [], guards: [] });\n    mockClientUser(this.client);\n\n    this.client.login = jest.fn(() => Promise.resolve('LOGIN_TOKEN')) as any;\n  }\n\n  private mockGuild(): void {\n    this.guild = mockGuild(this.client);\n  }\n  private mockChannel(): void {\n    this.channel = mockTextChannel(this.client, this.guild);\n  }\n\n  private mockUser(): void {\n    this.user = mockUser(this.client);\n  }\n}\n```\n","readmeFilename":"README.md"}