Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Supertest library.
NestJS
import request from '[1]';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'express' instead of 'supertest'.
Using 'jest' which is a test runner, not for HTTP requests.
✗ Incorrect
The supertest library is imported as request to perform HTTP requests in E2E tests.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a non-existent module like 'SupertestModule'.
Using 'HttpModule' which is for HTTP clients, not the app module.
✗ Incorrect
In NestJS E2E tests, you import the main AppModule to test the full application.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' or 'put' which are for sending data, not fetching.
Using 'delete' which removes data.
✗ Incorrect
To test a GET request, use the get method of Supertest.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong id like 2 or wrong name like 'Jane'.
Not matching the exact types (number vs string).
✗ Incorrect
The test checks if the response body array contains an object with id 1 and name 'John'.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST for sending data.
Expecting wrong status code like 200 instead of 201.
✗ Incorrect
Use post to send data, 'Alice' as the name in JSON, and expect HTTP status 201 for resource creation.