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.3

Testing Model Logic

In This Lesson

We'll learn how to Unit Test AdonisJS Model logic using Japa. We'll test a password reset token's validity to show instance-level tests. Then, we'll test its generate and verify methods to show static methods.

Created by
@tomgobich
Published

Models can have logic within them; sometimes this is a simple getter, and other times it's more complex methods. So, let's take a moment to cover how we can create unit tests to ensure this logic does what we expect.

node ace make:test models/password_reset_token --suite=unit

Within our PasswordResetToken we have a getter, isValid. This is a rather straightforward getter that you might not otherwise have a test for, but for educational purposes, let's test it anyway.

Join the Discussion 0 comments

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

Be the first to comment!