DEV Community

Cover image for TDD course with AdonisJs - 1. Let's build a reddit clone
Michael Z
Michael Z

Posted on • Updated on • Originally published at michaelzanggl.com

TDD course with AdonisJs - 1. Let's build a reddit clone

Originally posted at michaelzanggl.com. Subscribe to my newsletter to never miss out on new content.

AdonisJs is great for test driven development. Let's build an API for a simple version of reddit using TDD. It will consist of subforums, threads, comments and users. You can find the GitHub for it here: https://github.com/MZanggl/tdd-adonisjs/commit/b2582b286e4da0166f30a8d6a8eee7c3aeb1c8bb.

Without further ado, let's get the project set up!

Install CLI and framework

npm i -g @adonisjs/cli
Enter fullscreen mode Exit fullscreen mode

In this course we want to focus only on the adonis part and not the frontend, so let's create the project using the "api only" flag.

adonis new forum --api-only
cd forum
Enter fullscreen mode Exit fullscreen mode

Install testing library

Adonis comes with its own testing library, let's install it with

adonis install @adonisjs/vow
Enter fullscreen mode Exit fullscreen mode

We have to add the vowProvider under "start/app.js" in the aceProviders array to register the adonis test commands.

const aceProviders = [
    '@adonisjs/vow/providers/VowProvider',
]
Enter fullscreen mode Exit fullscreen mode

The installation of vow comes with an example test, run adonis test, npm test or simply npm t to run it.

To make sure things are working, run the project using adonis serve --dev and head to the url in your browser!


And that's all there is to it, in the next blog post we will create our first test!

Top comments (0)