Node.js
/Intermediate
Supertest
Definition
A Node.js library specifically designed to test HTTP servers (like Express apps). It allows you to simulate network requests without having to actually start the server on a port.
Explain Like I'm New
If Jest tests your internal functions, Supertest tests your external APIs. It acts like a fake web browser. You tell it: 'Send a POST request to `/login` with this JSON body, and verify that the server replies with a 200 Status Code and a Token'.
Real World Example
Testing Express endpoints. You pass your `app` object directly into Supertest. It boots up the app in memory, fires a request at it, measures the response, and shuts it down instantly.
Common Use Cases
- •API Integration Testing
- •Verifying HTTP status codes and JSON payloads
Interactive Example
Loading...
Console output will appear here...
Interview Questions
basic
- Do you need to call `app.listen()` to test an Express app with Supertest?
intermediate
- How does Supertest chain assertions?