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

Asserting JSON Structures

In This Lesson

We'll learn how to test fetching a list of items functionally. Assert a successful response, confirm the body is as we expect, check object structures, and loosely validate response data.

Created by
@tomgobich
Published

Notes Used to Craft this Lesson

What about testing a list of items? For this, we have our posts.index that returns an array of 3 different posts.

// app/controllers/posts_controller.ts
export default class PostsController {
  // ...

  async index() {
    return [
      {
        id: 1,
        title: 'My first post',
        summary: 'Lorem ipsum dolor sit amet, consectetur ...',
      },
      {
        id: 2,
        title: 'My second post',
        summary: 'Lorem ipsum dolor sit amet, consectetur ...',
      },
      {
        id: 3,
        title: 'My third post',
        summary: 'Lorem ipsum dolor sit amet, consectetur ...',
      },
    ]
  }

  // ...
}

Join the Discussion 0 comments

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

Be the first to comment!