0
0
NestJSframework~10 mins

Why testing ensures application reliability in NestJS - Test Your Understanding

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

Complete the code to import the testing module in a NestJS test file.

NestJS
import { Test, TestingModule } from '[1]';
Drag options to blanks, or click blank then click option'
A@nestjs/testing
Bnestjs/core
C@nestjs/common
Dnestjs/platform-express
Attempts:
3 left
💡 Hint
Common Mistakes
Importing from '@nestjs/common' instead of '@nestjs/testing'.
Using 'nestjs/core' which is not for testing.
2fill in blank
medium

Complete the code to create a testing module for the AppService.

NestJS
const module: TestingModule = await Test.createTestingModule({ providers: [[1]] }).compile();
Drag options to blanks, or click blank then click option'
AAppService
BAppController
CHttpService
DConfigService
Attempts:
3 left
💡 Hint
Common Mistakes
Providing the controller instead of the service.
Providing unrelated services.
3fill in blank
hard

Fix the error in the test by completing the code to get the service instance.

NestJS
const service = module.[1](AppService);
Drag options to blanks, or click blank then click option'
Afetch
Bfind
Cget
Dretrieve
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'find' which is not a method on TestingModule.
Using 'fetch' or 'retrieve' which do not exist here.
4fill in blank
hard

Fill both blanks to write a simple test that checks if the service is defined.

NestJS
it('should be defined', () => { expect(service).[1](); });
Drag options to blanks, or click blank then click option'
AtoBeFalsy
BtoBeTruthy
CtoBeNull
DtoBeDefined
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'toBeNull' which checks for null, not existence.
Using 'toBeFalsy' which checks for false-like values.
5fill in blank
hard

Fill all three blanks to write a test that checks the service returns the expected string.

NestJS
it('should return "Hello World!"', () => { expect(service.[1]()).[2]([3]); });
Drag options to blanks, or click blank then click option'
AgetHello
BtoEqual
C"Hello World!"
DtoBe
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'toBe' which is stricter and may fail for strings.
Using wrong method names or string values.