0
0
NestJSframework~10 mins

Testing module setup in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the TestingModule from NestJS.

NestJS
import { [1] } from '@nestjs/testing';
Drag options to blanks, or click blank then click option'
ATestModule
BTestingModule
CModuleTesting
DNestTesting
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect class names like TestModule or ModuleTesting.
Trying to import from other packages.
2fill in blank
medium

Complete the code to create a testing module with a service provider.

NestJS
const moduleRef = await Test.createTestingModule({ providers: [[1]] }).compile();
Drag options to blanks, or click blank then click option'
AMyService
BMyController
CAppModule
DNestService
Attempts:
3 left
💡 Hint
Common Mistakes
Adding controllers or modules as providers.
Using incorrect service names.
3fill in blank
hard

Fix the error in retrieving the service instance from the testing module.

NestJS
const service = moduleRef.[1](MyService);
Drag options to blanks, or click blank then click option'
Aget
Bfetch
Cretrieve
Dfind
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods like fetch or retrieve which do not exist on TestingModule.
Trying to access the service directly without using a method.
4fill in blank
hard

Fill both blanks to correctly import and create a testing module.

NestJS
import { [1] } from '@nestjs/testing';
const module = await [2].createTestingModule({}).compile();
Drag options to blanks, or click blank then click option'
ATest
BTestingModule
CTestModule
DNestTest
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing the import with TestingModule which is a class, not the utility object.
Using incorrect names like TestModule or NestTest.
5fill in blank
hard

Fill all three blanks to create a testing module, compile it, and retrieve a service.

NestJS
import { [1] } from '@nestjs/testing';

const moduleRef = await [2].createTestingModule({ providers: [MyService] }).compile();
const service = moduleRef.[3](MyService);
Drag options to blanks, or click blank then click option'
ATest
BTestingModule
Cget
DTestModule
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'TestingModule' as the utility object instead of 'Test'.
Using incorrect retrieval methods like 'fetch' or 'retrieve'.