0
0
Expressframework~5 mins

Mocking database calls in Express - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is mocking in the context of database calls?
Mocking means creating fake versions of database calls to test code without using a real database. It helps check if the code works correctly and quickly.
Click to reveal answer
beginner
Why do we mock database calls in Express apps?
We mock database calls to avoid slow or unreliable real database access during tests. It makes tests faster and safer by isolating the code from the database.
Click to reveal answer
intermediate
Which tool can you use to mock functions in Express tests?
You can use libraries like Sinon.js or Jest to create mocks and spies for database functions in Express tests.
Click to reveal answer
intermediate
How does mocking help when testing error handling in database calls?
Mocking lets you simulate errors from the database, so you can check if your code handles those errors properly without needing a real database failure.
Click to reveal answer
intermediate
What is a stub in mocking database calls?
A stub is a fake function that replaces a real database call and returns preset data or errors to control test scenarios.
Click to reveal answer
What is the main benefit of mocking database calls in Express tests?
AConnects to multiple databases
BImproves database performance
CAutomatically fixes database errors
DFaster and isolated tests without real database
Which library is commonly used to mock functions in JavaScript tests?
AExpress
BReact
CSinon.js
DMongoDB
What does a stub do in mocking?
AReplaces a function with preset responses
BDeletes the database
CRuns the real database query
DCreates a new database
How can mocking help test error handling?
ABy ignoring errors
BBy simulating database errors
CBy fixing errors automatically
DBy connecting to a backup database
When should you avoid mocking database calls?
AWhen you want to test real database integration
BWhen writing unit tests
CWhen testing error handling
DWhen running fast tests
Explain how mocking database calls improves testing in Express applications.
Think about speed and control in tests.
You got /4 concepts.
    Describe the difference between a mock and a stub when testing database calls.
    Focus on purpose and behavior tracking.
    You got /4 concepts.