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?
✗ Incorrect
Mocking helps tests run faster and isolates code from the real database.
Which library is commonly used to mock functions in JavaScript tests?
✗ Incorrect
Sinon.js is a popular library for mocking and spying on functions.
What does a stub do in mocking?
✗ Incorrect
A stub replaces a real function to return controlled data for tests.
How can mocking help test error handling?
✗ Incorrect
Mocking can simulate errors so you can check how your code reacts.
When should you avoid mocking database calls?
✗ Incorrect
Mocking is not used when you want to test actual database behavior.
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.