End-to-end tests verify the application through real request paths. This post is based on my original Medium article, Applying integration test on NestJS with Jest and GitHub Actions.
The example uses the NestJS auth flow project and focuses on testing the exposed controller behavior.
What e2e tests cover
Unlike unit tests, e2e tests start the NestJS application and call HTTP routes. They are useful for checking:
- request validation
- controller routing
- guards
- service integration
- authentication behavior
- response shape
They are slower than unit tests but protect the full request path.
Test setup
NestJS provides @nestjs/testing for creating a testing module and initializing the app in memory. Supertest can then call the HTTP server.
The test flow is:
- Create the testing module.
- Compile it.
- Initialize the Nest application.
- Call endpoints with Supertest.
- Assert status codes and response bodies.
- Close the app after tests.
GitHub Actions
Once the local e2e command works, CI can run it on pull requests. If the test requires Postgres, the workflow should define a database service or start one before executing the command.
That makes integration problems visible before merge.
Takeaways
Unit tests and e2e tests serve different purposes. For an auth flow, e2e tests are valuable because they validate how controllers, guards, services, and modules behave together.
