Package/lib for easly mocking djs ?

Hi Do you know an nodejs package that simplify mocking of djs things ? thx
13 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
WeeskyBDW
WeeskyBDWOP2y ago
i mean a lib that generate mocked object of djs main classes
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
WeeskyBDW
WeeskyBDWOP2y ago
Oups big delay, yeah i want an easy way to mock djs Rn it seem they is no node package who allow that
monbrey
monbrey2y ago
Mocking discord.js isn't really what you think it is - due to the way its dependencies work you'd really be trying to mock the rest and websocket layers Theres been attempts at it in the past but none are really successful
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
monbrey
monbrey2y ago
I guess the problem is how tightly wound everything is. TDD shouldn't mean that you need to be testing the Discord API or discord.js The event-driven style of discord.js though means that it isn't common for people to be writing functions that return an output. They tend to write event listeners which receive parameters, create all the embeds, buttons etc in the scope of that listener, and finish by making an API call If you wanted testable units, moving the creation of embeds and buttons to separate functions is one way to do that, but even then given discord.js has builders you'd really just be testing those
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
monbrey
monbrey2y ago
Yeah, which brings me back to it not being worth the amount of mocking that would require Oh yeah tightly coupling isn't a criticism It's just the way things tend to be written, because yeah it's very easy
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
monbrey
monbrey2y ago
The approach discord.js is moving towards with separate ws, rest, core etc modules would be easier to unit test, but the way the full package bundles them together, abstracts it away, maintains a populated cache Difficult to mock all that Especially just for some flow control
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
monbrey
monbrey2y ago
It generally makes more sense to test a bot using what would be considered end to end or system integration testing. Running it in a "non-prod" environment, like a Dev token and a test guild, and actually just use it. Run the commands, validate the outputs
Want results from more Discord servers?
Add your server