# Better test readability

If we look at the file <mark style="color:purple;">test</mark>/<mark style="color:purple;">domain</mark>/<mark style="color:purple;">users.e2e-spec</mark>, some overall similarities can be noticed with the unit tests. But now there is a variable for the <mark style="color:blue;">`app`</mark> itself, and instead of obtaining references from within the <mark style="color:blue;">`module`</mark>, it is used to initialize the <mark style="color:blue;">`app`</mark>. Also notice that just below, that default route, that was created with the project, is being tested. The **test's name** includes the **route's path** and its associated **HTTP method**. Then, the <mark style="color:blue;">`request`</mark> from the **supertest** library is used to simulate an actual request. It uses the <mark style="color:blue;">`server`</mark> from the <mark style="color:blue;">`app`</mark> in order to access the route with its HTTP method and, finally, <mark style="color:blue;">`expects`</mark> a certain <mark style="color:blue;">`status`</mark> and <mark style="color:blue;">`body`</mark>.

Very well! But before actually modifying this test file to accomodate user-related tests, let's make some improvements to its readability so that we can use this style afterwards. Let's then perform the following:

* Below the <mark style="color:blue;">`app`</mark> variable, create a variable for the <mark style="color:blue;">`server`</mark>

```typescript
let server: App;
```

* Obtain its reference after the <mark style="color:blue;">`app.init()`</mark> call

```typescript
server = app.getHttpServer();
```

* In the <mark style="color:blue;">`module`</mark>, import just the <mark style="color:blue;">`UsersModule`</mark> instead of the entire <mark style="color:blue;">`AppModule`</mark>

```typescript
imports: [UsersModule],
```

Then, in the test, we shall:

* Use the <mark style="color:blue;">`server`</mark> variable
* Put the result of the <mark style="color:blue;">`request()`</mark> call in a <mark style="color:blue;">`response`</mark>&#x20;
* Extract the <mark style="color:blue;">`status`</mark> and <mark style="color:blue;">`body`</mark> from the <mark style="color:blue;">`response`</mark>
* Use the enum for the <mark style="color:blue;">`status`</mark> instead of its code number
* Separate the <mark style="color:blue;">`expects`</mark> from the <mark style="color:blue;">`request()`</mark> call

Now, this is much more readable.

```typescript
it('/ (GET)', async () => {
  const response = await request(server).get('/');
  const { status, body } = response;

  expect(status).toBe(HttpStatus.OK);
  expect(body).toBe('Hello World!');
});
```

Let's then have an environment that resembles a real-world context before going to the tests.
