In the last lesson, we wrote a very basic test. In this lesson, we are going to look at how to run our tests.
What you'll learn
- Running all tests
- Running a single test
In the last lesson, we wrote a very basic test. In this lesson, we are going to look at how to run our tests.
We'll start by familiarizing ourselves with the concept of testing and then set up our AdonisJS application for testing using the Japa test runner.
In the last lesson, we wrote a very basic test. In this lesson, we are going to look at how to run our tests.
We have seen how to run tests, but there are times you'd prefer to have your tests running in watch mode. So whenever you make changes to a test file, the tests are rerun automatically. In this lesson, we'll cover how to achieve that using Nodemon.
During testing, AdonisJS will look for a dedicated test environment file called .env.testing
to fetch environment variables from. In this lesson, we create the file and take a closer look at it.
When building a non-trivial application, chances are we'll need to interact with a database in our tests. In this lesson, we are going to look at how to configure the Japa test runner to interact with a database. We'll be covering two ways to achieve that.
With all the setup out of the way, let's start writing actually tests for our application. In this lesson, we'll start with a unit test that will test the User model to ensure users' passwords are hashed when saved to the database.
Iām a self-taught software developer based in Lagos, Nigeria, with over 8 years of experience. In the last couple of years, I've been doing more teaching because I enjoy sharing my knowledge so that others can benefit from it. Come along as I teach you all I know about AdonisJS, Node.js, and JavaScript at large!
No comments yet.