Node.js / NestJS

End-to-End Testing

Supertest, test database, fixtures, authentication in tests, API testing

20 câu hỏi phỏng vấn·
Mid-Level
1

What is an E2E (end-to-end) test in the context of NestJS?

Câu trả lời

An E2E test validates the complete application flow, from HTTP request to response, through all layers (controller, service, database). Unlike unit tests that isolate a component, E2E tests verify that the integration of all components works correctly. This helps detect integration bugs that unit tests cannot capture.

2

What is the recommended library by NestJS for E2E testing?

Câu trả lời

Supertest is the recommended library for E2E testing in NestJS because it allows testing HTTP endpoints without starting the server on a network port. It creates an isolated application instance and sends simulated HTTP requests directly. This makes tests faster, more reliable, and avoids port conflicts between parallel tests.

3

How to get the HTTP server instance for Supertest in a NestJS test?

Câu trả lời

The app.getHttpServer() method returns the underlying HTTP server instance (Express or Fastify) that can be passed to Supertest to make test requests. This method is available after creating the test module with Test.createTestingModule(). It allows Supertest to directly access the server without having to start it on a network port.

4

In which file are E2E tests typically placed in a NestJS project?

5

Which Supertest method allows checking the status code of an HTTP response?

+17 câu hỏi phỏng vấn

Nắm vững Node.js / NestJS cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí