Integration testing in NestJS checks how different parts of the application work together, like controllers, services, and modules, to ensure they interact correctly.
Click to reveal answer
beginner
Which NestJS testing utility helps create a testing module for integration tests?
The Test.createTestingModule() method helps build a testing module that mimics the real module setup for integration testing.
Click to reveal answer
intermediate
Why do we use beforeEach or beforeAll hooks in NestJS integration tests?
These hooks set up the testing environment before each or all tests run, like creating the testing module and initializing the app instance.
Click to reveal answer
intermediate
How do you test HTTP endpoints in NestJS integration tests?
You use the supertest library to send HTTP requests to the NestJS app instance and check the responses to verify endpoint behavior.
Click to reveal answer
beginner
What is the difference between unit testing and integration testing in NestJS?
Unit testing checks individual parts in isolation, while integration testing checks how multiple parts work together in the app.
Click to reveal answer
Which method creates a testing module in NestJS integration tests?
AModule.forRoot()
BTest.createTestingModule()
CNestFactory.create()
DAppModule.init()
✗ Incorrect
Test.createTestingModule() builds a testing module for integration tests.
What library is commonly used to test HTTP requests in NestJS integration tests?
Arequest-promise
Baxios
Cjest-fetch-mock
Dsupertest
✗ Incorrect
supertest sends HTTP requests to the NestJS app during integration tests.
In NestJS, where do you usually initialize the app instance for integration testing?
AInside the controller constructor
BInside the main.ts file
CInside beforeEach or beforeAll hooks
DInside the service provider
✗ Incorrect
beforeEach or beforeAll hooks set up the app instance before tests run.
Integration testing in NestJS mainly focuses on:
ATesting how modules and services work together
BTesting database schema only
CTesting UI components
DTesting individual functions only
✗ Incorrect
Integration tests check interaction between modules and services.
Which of these is NOT a typical step in NestJS integration testing setup?
ADirectly modifying production database
BCreating a testing module
CUsing supertest to send HTTP requests
DInitializing the Nest app instance
✗ Incorrect
Tests should avoid modifying the production database.
Explain how to set up a basic integration test in NestJS for an HTTP endpoint.
Think about how you prepare the app and send requests to test endpoints.
You got /4 concepts.
Describe the main difference between unit testing and integration testing in NestJS.
Focus on scope and interaction of tested parts.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of integration testing in NestJS?
easy
A. To test individual functions in isolation
B. To check how different parts of the application work together
C. To measure application performance under load
D. To check the syntax of TypeScript code
Solution
Step 1: Understand integration testing goal
Integration testing focuses on verifying that multiple parts of the app interact correctly.
Step 2: Differentiate from other test types
Unit tests check single functions; performance tests measure speed; syntax checks are done by compilers.
Final Answer:
To check how different parts of the application work together -> Option B
Quick Check:
Integration testing = check parts working together [OK]
Hint: Integration tests check combined parts, not single functions [OK]
Common Mistakes:
Confusing integration with unit testing
Thinking integration tests check performance
Believing integration tests check code syntax
2. Which of the following is the correct way to initialize a NestJS application for integration testing?
easy
A. const app = await Test.createTestingModule({ imports: [AppModule] }).start();
B. const app = new AppModule(); app.start();
C. const app = await Test.createTestingModule({ controllers: [AppController] }).init();