0
0
Node.jsframework~10 mins

Integration testing patterns in Node.js - 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 library for integration tests.

Node.js
import [1] from 'supertest';
Drag options to blanks, or click blank then click option'
Arequest
Bexpress
Cjest
Dmocha
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the test runner instead of the HTTP request library.
Using 'express' which is the server framework, not the testing tool.
2fill in blank
medium

Complete the code to start the server before running integration tests.

Node.js
beforeAll(async () => {
  server = app.[1](3000);
});
Drag options to blanks, or click blank then click option'
Alisten
Bstart
Copen
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'start' or 'run' on the app object.
Not starting the server before tests, causing connection errors.
3fill in blank
hard

Fix the error in the test by completing the assertion method.

Node.js
expect(response.status).to[1](200);
Drag options to blanks, or click blank then click option'
Aequal
Bbe
CtoBe
Dequals
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'equal' or 'equals' which are not Jest matchers.
Using 'be' which is incomplete and causes syntax errors.
4fill in blank
hard

Fill both blanks to create a test that sends a POST request with JSON data.

Node.js
await request(app)
  .post('/api/data')
  .set('Content-Type', '[1]')
  .send({ key: 'value' })
  .expect([2]);
Drag options to blanks, or click blank then click option'
Aapplication/json
Bapplication/xml
C200
D404
Attempts:
3 left
💡 Hint
Common Mistakes
Setting wrong content type like 'application/xml'.
Expecting wrong status codes causing test failures.
5fill in blank
hard

Fill all three blanks to write a test that checks the response body for a specific property.

Node.js
test('response has user id', async () => {
  const response = await request(app).get('/user/123');
  expect(response.body).toHaveProperty('[1]');
  expect(typeof response.body.id).to[2]('string');
  expect(response.body.id).not.to[3]('');
});
Drag options to blanks, or click blank then click option'
Aid
Bbe
CtoBe
Dequal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'be' which is not a valid Jest matcher.
Mixing up 'equal' and 'toBe' causing test errors.