NestJS · Junior · Question 48 of 75
How do you create a testing module in Nest?
const moduleRef = await Test.createTestingModule({
controllers: [UsersController],
providers: [UsersService],
}).compile();- ✓Correct answer: With
Test.createTestingModule()from@nestjs/testing, thencompile()and get instances withmoduleRef.get() - 2Start the whole app with
node main.jsbefore each test - 3Nest code can't be unit tested
Explanation
The testing module builds a small DI container with just what the test needs.