In what scenarios would using spies be preferable over mocks and stubs?
- When you need to assert on method invocations
- When you need to control the return value of a function
- When you want to isolate the code under test
- When you want to use real implementations
Using spies is preferable over mocks and stubs when you need to assert on method invocations, as spies can record and report on method calls without altering the original method behavior. Mocks and stubs are more focused on controlling method behavior. Options 2, 3, and 4 are not typical scenarios for using spies.
Loading...
Related Quiz
- In Express.js, how can you handle errors occurring in asynchronous code within a route handler?
- You are developing a high-traffic e-commerce website. You need to implement a caching strategy to ensure that the load on the database is minimized, and the data retrieval is fast. Which caching strategy would be most suitable, and why?
- Which Node.js feature can help in improving the performance of CPU-bound tasks?
- You are developing an application with multiple user roles, and each role has different levels of access to resources. How would you securely implement role-based access control to prevent unauthorized access?
- How can specific error handlers be created to respond to different error types in Express.js?