# Chapter 10: Testing our API

> Every time you've ever filled a form and you expect to see some kind of notification panel at the top, you are testing. Everyone agrees that testing is good, the only question is, is automated testing good? Why would the answer ever be no? Or think of it this way, why would it ever be a bad thing to have this huge group of tests that backup everything you write.
>
> *-Jeffrey Way, Founder of Laracasts.com*

At this point, we've written the code for our RESTful API. The only problem is that we don't have any automated tests to back them up. In this chapter, ***we'll demonstrate how to test each layer of our API*** and we'll see just how easy and efficient a layered architecture application is able to incorporate automated tests. Since there are way too many files and features to test, we'll keep it simple and consistent, we'll be mainly focused on writing tests for the **user registration endpoint**.

### Before We Begin

We will be using [JEST](https://jestjs.io) as our testing framework of choice.

All tests will be written in a `__tests__` folder depending on which layer we'll be testing except for API integration tests which will be located in the `tests` directory of the root folder. You can find all the configuration settings in the `config/jest.config.js` file.

Tests can be ran by following the instructions on the [README page of the GitHub repository.](https://github.com/restful-node/restful-nodejs-app#running-tests) Make sure to install the application and have it running locally before running the tests.

There is a Git Actions setup for continuous integration for this project. You may find it here at: <https://github.com/restful-node/restful-nodejs-app/actions>.

Do note that this is not a complete course on testing, if you want to learn more about testing and testing in JavaScript, I recommend taking the course <https://testingjavascript.com> by Kent C. Dodds.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.restfulnode.com/part-3/chapter-10.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
