Testing the Application with the API Client

Learn how to test any application integrated with a client API.

We'll cover the following

Previously, when we created our JavaScript client, we mentioned that one of the advantages of having it living in the API code base is that we could easily write tests for the client and the API to guarantee that they work well together. In this lesson, we’ll demonstrate how we can do this. For these tests, instead of using fetch and doing raw requests, we’ll use the API client we created.

When we provide an API client to our users, we have the responsibility of making sure it works flawlessly with our application. One of the ways to guarantee this is by having a complete test suite, one that not only tests the client on its own but also tests its integration with the API. Here we’ll take care of the latter.

Steps to test the API client

We’ll use one feature of the API client and create a test that makes sure it’s working. Once again, there will be some similarities between these and the tests we wrote previously. We’ll replicate the logic from the previous tests, but this time we’ll use the client. Let’s get started:

  1. Inside the same src/index.test.ts file, create a new test for the login functionality:

Get hands-on with 1200+ tech skills courses.