Node.js · Middle · Question 56 of 75
How do you test an Express app's endpoints without starting a real server on a fixed port?
- 1Endpoints can only be tested manually
- 2Mock the
httpmodule completely - ✓Correct answer: Pass the
appto a library like Supertest, or start it on port 0 and call it withfetch
Explanation
Port 0 lets the OS pick a free port, so tests can run in parallel. Export the app separately from the listen() call to make this easy.