0
0
NestJSframework~10 mins

E2E testing with supertest 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 Supertest library.

NestJS
import request from '[1]';
Drag options to blanks, or click blank then click option'
Asupertest
Bjest
Cexpress
Dhttp
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'express' instead of 'supertest'.
Using 'jest' which is a test runner, not for HTTP requests.
2fill in blank
medium

Complete the code to create a NestJS testing module for E2E tests.

NestJS
const moduleRef = await Test.createTestingModule({ imports: [[1]] }).compile();
Drag options to blanks, or click blank then click option'
AHttpModule
BTestingModule
CSupertestModule
DAppModule
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a non-existent module like 'SupertestModule'.
Using 'HttpModule' which is for HTTP clients, not the app module.
3fill in blank
hard

Fix the error in the test to correctly send a GET request to '/users'.

NestJS
return request(app.getHttpServer()).[1]('/users').expect(200);
Drag options to blanks, or click blank then click option'
Aput
Bpost
Cget
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' or 'put' which are for sending data, not fetching.
Using 'delete' which removes data.
4fill in blank
hard

Fill both blanks to check the response body contains a user with id 1.

NestJS
expect(response.body).toEqual(expect.arrayContaining([expect.objectContaining({ id: [1], name: [2] })]));
Drag options to blanks, or click blank then click option'
A1
B'John'
C'Jane'
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong id like 2 or wrong name like 'Jane'.
Not matching the exact types (number vs string).
5fill in blank
hard

Fill all three blanks to send a POST request with JSON body and check status 201.

NestJS
return request(app.getHttpServer()).[1]('/users').send({ name: [2] }).expect([3]);
Drag options to blanks, or click blank then click option'
Apost
B'Alice'
C201
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST for sending data.
Expecting wrong status code like 200 instead of 201.