0
0
NestJSframework~5 mins

Test database strategies in NestJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AExact replication of production behavior
BData persists after tests finish
CFaster test execution
DRequires complex setup
What should you do before each test when using a test database?
ASeed or reset the database
BLeave data as is
CDelete the entire database
DRun tests in parallel without setup
Why is it important to close database connections after tests in NestJS?
ATo keep connections open for faster tests
BTo free resources and avoid memory leaks
CTo prevent tests from running
DIt is not necessary
Which strategy helps isolate test data from production data?
ANot using a database in tests
BRunning tests on production database
CSharing the same database for all environments
DUsing a separate test database
What is a downside of using a real test database compared to an in-memory one?
ASlower test execution
BData is lost after tests
CCannot run queries
DNo need for setup
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.