0
0
NestJSframework~10 mins

Integration testing 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 testing module for integration tests in NestJS.

NestJS
import { Test, TestingModule } from '@nestjs/[1]';
Drag options to blanks, or click blank then click option'
Atesting
Btest
Ctests
Dtest-module
Attempts:
3 left
💡 Hint
Common Mistakes
Using '@nestjs/test' instead of '@nestjs/testing'
Misspelling the package name
2fill in blank
medium

Complete the code to create a testing module with the AppModule imported.

NestJS
const moduleRef: TestingModule = await Test.createTestingModule({ imports: [[1]] }).compile();
Drag options to blanks, or click blank then click option'
AappModule
BAppModule
CApplicationModule
DMainModule
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'appModule' which is invalid
Using incorrect module names like 'MainModule'
3fill in blank
hard

Fix the error in the code to get the service instance from the testing module.

NestJS
const service = moduleRef.[1](MyService);
Drag options to blanks, or click blank then click option'
AgetService
Bfetch
Cretrieve
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'getService' or 'retrieve'
Confusing with HTTP fetch method
4fill in blank
hard

Fill both blanks to correctly initialize and close the NestJS application in the test.

NestJS
app = moduleRef.[1]();
await app.[2]();
Drag options to blanks, or click blank then click option'
AcreateNestApplication
Binit
Cclose
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'init' instead of 'createNestApplication' to create app
Using 'start' instead of 'close' to shut down app
5fill in blank
hard

Fill all three blanks to write a test that checks if the service method returns the expected value.

NestJS
it('should return expected result', async () => {
  const result = await service.[1]();
  expect(result).[2]([3]);
});
Drag options to blanks, or click blank then click option'
AgetData
BtoEqual
C'expected value'
DtoBe
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'toBe' which checks identity instead of 'toEqual' for value equality
Using wrong method names on service