Recall & Review
beginner
What is the purpose of using a test database in NestJS applications?
A test database isolates test data from production data, ensuring tests run safely without affecting real users or data. It helps verify database interactions in a controlled environment.
Click to reveal answer
intermediate
What is the difference between an in-memory database and a real test database?
An in-memory database stores data temporarily in memory and is fast but may not mimic all real database behaviors. A real test database runs on disk and behaves like production but is slower and needs setup.
Click to reveal answer
beginner
How does the 'beforeEach' hook help in test database strategies?
The 'beforeEach' hook resets or seeds the test database before each test, ensuring tests start with a clean and predictable state for reliable results.
Click to reveal answer
intermediate
Why is it important to clean up the test database after tests?
Cleaning up prevents leftover data from affecting other tests, avoids memory leaks, and keeps the test environment consistent and reliable.
Click to reveal answer
intermediate
What is a common strategy to handle database connections in NestJS tests?
Use a dedicated test module to create and manage database connections, often with a separate test database URL, and close connections after tests to free resources.
Click to reveal answer
Which of the following is a benefit of using an in-memory test database?
✗ Incorrect
In-memory databases are fast because they store data in memory, but they may not replicate all production behaviors exactly.
What should you do before each test when using a test database?
✗ Incorrect
Resetting or seeding the database before each test ensures a clean state and reliable test results.
Why is it important to close database connections after tests in NestJS?
✗ Incorrect
Closing connections frees resources and prevents memory leaks, keeping the test environment stable.
Which strategy helps isolate test data from production data?
✗ Incorrect
A separate test database keeps test data isolated and safe from production data.
What is a downside of using a real test database compared to an in-memory one?
✗ Incorrect
Real test databases run on disk and are slower than in-memory databases but provide more accurate behavior.
Explain how you would set up a test database strategy in a NestJS project.
Think about isolation, setup, and cleanup steps.
You got /4 concepts.
Describe the advantages and disadvantages of using an in-memory database for testing in NestJS.
Compare speed and realism.
You got /2 concepts.