šŸŽ‰ To celebrate crossing 1k users, Adonis Mastery Pro is 50% off all through August. Go Pro!

Want to have access to everything?

Go PRO to have access to this lesson and the entire Adonis Mastery library. Already a PRO? Sign in to continue learning!

Using a dedicate test env file

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.

What you'll learn

  • Use a dedicate test environment file

Testing AdonisJS

35mins
6 lessons
Beginner

Getting Started

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.

What you'll learn

  • What is testing
  • Benefit of testing
  • Set up the Japa test runner in an AdonisJS application

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

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.

What you'll learn

  • How to run tests in watch mode 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.

What you'll learn

  • Use a dedicate test environment file

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.

What you'll learn

  • Configure Japa to interact with a database
  • use a dedicate database for testing
  • Run migrations programmatically

Tests

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.

What you'll learn

  • What is a unit test
  • What is a integration test
  • Running migrations on a need-to basis
  • Ensure each test starts on a clean slate
  • Write your first AdonisJS test
Chimezie Enyinnaya

Hi, I'm Chimezie Enyinnaya, your teacher.

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!

Lesson video (SD)
Lesson video (HD)

No comments yet.