Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Bubbles64766yOkay I have a question, so I know what they are but I don’t know how to write a unit test and how to implement it I to my projects and when. Is there any resources you could point me to that’ll help me with it? I haven’t found good ones -
@Bubbles I also just got into them ^^
I wrote those with mocha, a TDD tool for Node.js.
suite("Danbooru", () => {
test("Danbooru blocks non-NSFW", (done) => {
danbooruCommand.content(["cute"], false).then(msg => {
assert.equal(msg.startsWith(":x: Sorry,"), true);
done();
});
});
});
This small code starts a new test category named "Danbooru" and a test named "Danbooru blocks non-NSFW".
The test executes a function, gets the return value and asserts whether it starts with ":x:Sorry,". Then it calls done() and the assert result is used as test result. -
Bubbles64766y@PrivateGER so does something in the current code call this new file that the test is in and then tests each one (if there are more than one in a file) -
Not quite.
Tests are all collected in a seperate "test" directory.
mocha runs all the JS files found in it.
Tests must run completely seperate from the main code, otherwise you break the testing environment. -
Would it be at all possible to get some more insight as how you wrote your unit tests? Did you mock data?
Related Rants


What only relying on JavaScript for HTML form input validation looks like
Found something true as 1 == 1
I finally stopped being lazy and wrote 31 unit tests for my Discord bot.
Nothing is more satisfying than seeing them all pass and the GitHub workflow working without any problems. :)
random
js
unit test