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 #3.4

Testing Ace Console Commands

In This Lesson

We'll learn how to test AdonisJS Ace Commands with Japa. We'll cover how to instantiate and execute the command, while passing arguments and capturing prompts. We'll also discuss asserting logged statements sent from the command.

Created by
@tomgobich
Published

Notes Used to Craft this Lesson

Okay, so our project has a super simple greet Ace Command which we can use to quickly show how you can go about testing commands.

// commands/greet.ts
import { args, BaseCommand } from '@adonisjs/core/ace'
import type { CommandOptions } from '@adonisjs/core/types/ace'

export default class Greet extends BaseCommand {
  static commandName = 'greet'
  static description = 'Prints a greeting to the name provided'

  static options: CommandOptions = {}

  @args.string()
  declare name: string

  async run() {
    this.logger.log(`Hello ${this.name}!`)
  }
}

Join the Discussion 0 comments

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

Be the first to comment!