Ready to get started?

Join Adocasts Plus for $8/mo, or sign into an existing Adocasts Plus account, to get access to all of our lessons.

robot mascot smiling

Pragmatic Testing in AdonisJS with Japa #5.2

Testing with Lucid Model Factories

In This Lesson

We'll learn about AdonisJS Model Factories and how we can use them to create realistic, yet fake, test data. We'll create a few factories we'll use in this series and learn how we can stub or create data with them in tests.

Created by
@tomgobich
Published

In the last lesson, we manually defined our users' properties, their full name, email, and password. That's ok for the small amount of data needed for our users, but this can get very excessive with larger models. To help with this, we can introduce factories.

Factories allow us to create real model instances and rows within our database using fake data. This will allow us to create a user by simply calling:

const user = await UserFactory.create();

Join the Discussion 0 comments

Create a free account to join in on the discussion
robot comment bubble

Be the first to comment!