Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import Express in a test file.
Express
const express = require('[1]');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' instead of 'express' for import.
✗ Incorrect
You import Express by requiring the 'express' package.
2fill in blank
mediumComplete the code to import the testing function from Vitest.
Express
const { [1] } = require('vitest'); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' or 'start' which are not test functions.
✗ Incorrect
The 'test' function is used to define test cases in Vitest.
3fill in blank
hardFix the error in importing the supertest library for HTTP testing.
Express
const request = require('[1]');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect package names like 'supertest-express'.
✗ Incorrect
The correct package name for HTTP testing with Express is 'supertest'.
4fill in blank
hardFill both blanks to create a simple test that checks the Express app response status.
Express
test('GET / responds with 200', async () => { const response = await request([1]).get('/'); expect(response.status).toBe([2]); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'server' instead of 'app' or wrong status codes.
✗ Incorrect
We use the Express app instance to send requests and expect a 200 status for success.
5fill in blank
hardFill all three blanks to setup a Vitest test file with Express and supertest.
Express
const express = require('[1]'); const request = require('[2]'); const { test, expect } = require('[3]');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing Jest with Vitest imports or wrong package names.
✗ Incorrect
We import Express, supertest for HTTP testing, and Vitest functions for testing.