Challenge - 5 Problems
Supertest E2E Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this NestJS E2E test using Supertest?
Consider this E2E test snippet for a NestJS controller endpoint that returns a JSON object with a greeting message. What will the test output be when run?
NestJS
return request(app.getHttpServer()) .get('/hello') .expect(200) .expect('Content-Type', /json/) .expect({ message: 'Hello, world!' });
Attempts:
2 left
💡 Hint
Check the expected status code and JSON body in the test.
✗ Incorrect
The test expects a 200 status and a JSON response with the exact message. If the controller returns this correctly, the test passes.
📝 Syntax
intermediate2:00remaining
Which option correctly uses Supertest to test a POST request with JSON body in NestJS?
You want to test a POST endpoint '/users' that accepts a JSON body with a 'name' property. Which code snippet correctly sends the JSON body and expects a 201 status?
Attempts:
2 left
💡 Hint
Supertest uses .send() to send JSON bodies by default.
✗ Incorrect
Option B correctly uses .send() to send JSON and expects status 201. Option B uses .body() which is invalid. Option B uses .json() which is not a Supertest method. Option B sets wrong Content-Type.
🔧 Debug
advanced2:00remaining
Why does this NestJS E2E test with Supertest fail with a timeout?
This test tries to GET '/items' but never completes and times out. What is the most likely cause?
NestJS
it('should return items', () => { return request(app.getHttpServer()) .get('/items') .expect(200) .expect(res => { expect(res.body.length).toBeGreaterThan(0); }); });
Attempts:
2 left
💡 Hint
Check if the app instance is properly created and listening before tests.
✗ Incorrect
If the NestJS app is not initialized or started, Supertest cannot connect, causing a timeout. The test code itself is correct.
❓ state_output
advanced2:00remaining
What is the value of 'createdUserId' after this E2E test runs?
This test creates a user and saves the returned id in 'createdUserId'. What will be the value of 'createdUserId' after the test?
NestJS
let createdUserId; it('creates a user', async () => { const response = await request(app.getHttpServer()) .post('/users') .send({ name: 'Bob' }) .expect(201); createdUserId = response.body.id; });
Attempts:
2 left
💡 Hint
Check what the server returns in the response body after creating a user.
✗ Incorrect
The test assigns response.body.id to 'createdUserId'. If the server returns the new user's id, it will be stored correctly.
🧠 Conceptual
expert3:00remaining
Which statement best describes the role of Supertest in NestJS E2E testing?
Choose the most accurate description of how Supertest works within NestJS E2E tests.
Attempts:
2 left
💡 Hint
Think about how E2E tests simulate real user interactions.
✗ Incorrect
Supertest sends real HTTP requests to the running NestJS app server, testing the full request-response cycle.