Skip to content

Commit 8a88e6c

Browse files
author
Yousef Sultan
committed
docs(fundamentals/unit-testing): Add hint for Fastify configuration for E2E testing
Signed-off-by: Yousef Sultan <[email protected]>
1 parent 8cb2d73 commit 8a88e6c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

content/fundamentals/unit-testing.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,17 @@ describe('Cats', () => {
239239
});
240240
```
241241

242+
> info **Hint** If you're using [Fastify](/techniques/performance) as your HTTP adapter, it requires slightly different configuration:
243+
>
244+
> ```ts
245+
> app = moduleRef.createNestApplication<NestFastifyApplication>(
246+
> new FastifyAdapter(),
247+
> );
248+
>
249+
> await app.init();
250+
> await app.getHttpAdapter().getInstance().ready();
251+
> ```
252+
242253
In this example, we build on some of the concepts described earlier. In addition to the `compile()` method we used earlier, we now use the `createNestApplication()` method to instantiate a full Nest runtime environment. We save a reference to the running app in our `app` variable so we can use it to simulate HTTP requests.
243254
244255
We simulate HTTP tests using the `request()` function from Supertest. We want these HTTP requests to route to our running Nest app, so we pass the `request()` function a reference to the HTTP listener that underlies Nest (which, in turn, may be provided by the Express platform). Hence the construction `request(app.getHttpServer())`. The call to `request()` hands us a wrapped HTTP Server, now connected to the Nest app, which exposes methods to simulate an actual HTTP request. For example, using `request(...).get('/cats')` will initiate a request to the Nest app that is identical to an **actual** HTTP request like `get '/cats'` coming in over the network.

0 commit comments

Comments
 (0)