# Testing an API

You've been running tests since the first exercise; now write them. Test functions with Node's own test runner, then test a whole API end to end with Supertest: requests in, responses out, errors included, with a fresh start for every test.

Updated: November 19, 2026

## [Tests with node --test](https://www.ask-codey.com/courses/nodejs-in-depth/topics/node-test-runner)

1. [Your First Tests with node --test](https://www.ask-codey.com/lessons/node-testing-first-tests) (Apprentice): A test is a few lines of code that run your code and check its answer, and Node's built-in test runner, node --test, runs every test file and reports what passed and what didn't.

## [Testing an API End to End](https://www.ask-codey.com/courses/nodejs-in-depth/topics/node-testing-apis)

1. [Testing an API with Supertest](https://www.ask-codey.com/lessons/node-testing-supertest) (Journeyman): Supertest hands a request straight to an Express app, with no server running and no port, so a test can check the status code, the headers and the JSON body that come back, for a GET and for a POST with a body.
2. [Testing Errors, with a Fresh Start for Every Test](https://www.ask-codey.com/lessons/node-testing-errors-and-fresh-state) (Journeyman): An API's error answers, such as 400, 404 and 409 with their JSON bodies, are part of what it promises, so they get tests too, and beforeEach puts the in-memory data back before every test, so each one starts from the same seats.

## [Exercise: Concert Tickets API Tests](https://www.ask-codey.com/courses/nodejs-in-depth/topics/exercise-node-concert-tickets-api-tests)

1. [Exercise: Concert Tickets API Tests](https://www.ask-codey.com/lessons/exercise-node-concert-tickets-api-tests) (Journeyman): Write the Supertest tests for Starlight Stage's working tickets API, from its shows to buying tickets, its errors and refunds, and prove they're good by catching three bugs the check plants in the API.

## [Up Next: Data with MongoDB](https://www.ask-codey.com/courses/nodejs-in-depth/topics/node-up-next-data-with-mongodb)

1. [Up Next: Data with MongoDB](https://www.ask-codey.com/lessons/node-up-next-data-with-mongodb) (Apprentice): See how much of an API you can build after Module 2, meet the Library Loans API project where you'll show it, and find out why Module 3 moves an API's data into MongoDB.

Source: https://www.ask-codey.com/courses/nodejs-in-depth/chapters/node-testing-an-api
