Recall & Review
beginner
What is the main purpose of using Jest or Vitest with an Express app?
They help test your Express app's code automatically to catch errors early and ensure it works as expected.
Click to reveal answer
beginner
Which file usually contains the Express app setup for testing?
A separate file like <code>app.js</code> or <code>server.js</code> exports the Express app so tests can import it without starting the server.Click to reveal answer
intermediate
How do you tell Jest or Vitest to run tests in a Node environment for Express?
Set the test environment to
node in the config file or use @jest-environment node at the top of test files.Click to reveal answer
intermediate
What is the role of
supertest in testing Express apps with Jest or Vitest?supertest simulates HTTP requests to your Express app so you can test routes and responses without running a real server.Click to reveal answer
beginner
How do you run tests with Vitest after setup?
Use the command
npx vitest or add a script like "test": "vitest" in package.json and run npm test.Click to reveal answer
Which package helps simulate HTTP requests to test Express routes?
✗ Incorrect
supertest is used to simulate HTTP requests in tests for Express apps.
What environment should Jest or Vitest use to test Express apps?
✗ Incorrect
Express apps run on Node.js, so the test environment must be set to node.
Where should you export your Express app for testing?
✗ Incorrect
Exporting the app from a separate file allows tests to import it without starting the server.
Which command runs Vitest tests if configured in
package.json scripts?✗ Incorrect
npm test runs the test script, which can be set to vitest.
Why avoid starting the Express server in test files?
✗ Incorrect
Starting the server can slow tests, cause conflicts, and reduce test isolation.
Explain how to set up Jest or Vitest to test an Express app's routes.
Think about how to import the app, simulate requests, and configure the test runner.
You got /4 concepts.
Describe why using supertest is helpful when testing Express apps with Jest or Vitest.
Imagine testing your app's web pages without opening a browser.
You got /3 concepts.