Learn how to test RESTful APIs built with Strapi using the Mocha testing framework and the Chai assertion library.
Testing is a fundamental building block that is often overlooked when developing applications. It gives the user a measure of assurance as to the quality of the finished product and usually helps uncover errors.
In this tutorial, we’ll go over how to test RESTful APIs built with Strapi, which is an open-source headless JavaScript CMS. It’s used to build customizable API’s quickly and without worrying much about the details of the underlying architecture.
We will use the Mocha testing framework and the Chai assertion library to test the endpoints built on Strapi.
This tutorial assumes the you have the following:
To get started using Strapi, open your terminal and run the following to install.
npx create-strapi-app strapi-mocha-chai --quickstart
The above command will initialize a Strapi project called strapi-mocha-chai
. The --quicktart
flag will initialize Strapi with an Sqlite database. If you want to be able to select a database of your choice, omit the flag.
After installation, the app should start automatically. If it doesn’t, run npm develop
to start it.
Navigate to http://localhost:1337/
on your browser to view the application. You should see a screen like the one below.
Fill the form and submit it. After submitting, it takes you to the dashboard, where you can start creating API endpoints.
#testing #api #strapi #mocha #chai