Search⌘ K
AI Features

E2E Tests for a Sign-Up Scenario

Explore how to create comprehensive end-to-end tests for a user sign-up process in NestJS. Understand testing successful registration, handling duplicate emails, validating email formats, and enforcing password rules to ensure robust authentication. This lesson helps you confirm your authentication system works as expected under different scenarios.

With the configuration set up, let’s write our E2E tests for the sign-up scenario.

Test: Successful registration

In this test, we’ll verify if a new user can successfully sign up. We’ll send a request with a unique email and password and expect the system to create a new user account.

DATABASE_USER=postgres
DATABASE_PASSWORD=pwd123
DATABASE_PORT=5432
DATABASE_HOST=localhost
DATABASE_NAME=test_database
JWT_SECRET=*3:DX*5,M2`j_q{n>je6
JWT_EXPIRES_IN=3600
E2E test for successful user registration

We’re using request to send a POST request to the /auth/signup endpoint. The .send method includes the new user credentials. We expect a 201 Created status, indicating successful registration, as seen in lines 26–31.

Press the “Run” button to launch the test.

As we can see, ...