Recall & Review
beginner
What is dependency injection in Angular service testing?
Dependency injection is a design pattern where Angular provides the required service instances to a component or another service automatically, making it easier to test by injecting mock or real services.
Click to reveal answer
beginner
How do you inject a service into a test in Angular?
You use Angular's TestBed.configureTestingModule to provide the service, then inject it using TestBed.inject(ServiceName) inside your test setup.
Click to reveal answer
intermediate
Why use mocks or spies when testing services with dependency injection?
Mocks or spies replace real dependencies to isolate the service being tested, allowing control over external calls and verifying interactions without side effects.
Click to reveal answer
beginner
What is the role of TestBed in Angular service testing?
TestBed sets up an Angular testing environment, allowing you to configure providers and inject services for isolated and controlled testing.
Click to reveal answer
intermediate
How can you test a service method that depends on another service?
Inject the dependent service as a mock or spy using TestBed providers, then test the main service method by controlling the mock's behavior and verifying outcomes.
Click to reveal answer
Which Angular class helps configure the testing environment for services?
✗ Incorrect
TestBed is used to configure and initialize the environment for Angular tests, including service injection.
How do you replace a real service with a mock in Angular tests?
✗ Incorrect
You provide the mock service in the TestBed configuration to replace the real service during testing.
What method is used to get an instance of a service in Angular tests?
✗ Incorrect
TestBed.inject() returns the instance of the requested service from the testing injector.
Why is dependency injection helpful in testing Angular services?
✗ Incorrect
Dependency injection allows you to replace real dependencies with mocks or spies, making tests isolated and predictable.
What is a spy in Angular testing?
✗ Incorrect
A spy is a test double that records how a function is called, useful for verifying interactions in tests.
Explain how to set up and inject a service for testing in Angular using dependency injection.
Think about how Angular provides services automatically and how TestBed helps in tests.
You got /4 concepts.
Describe why and how you would use mocks or spies when testing a service that depends on another service.
Consider how to avoid calling real dependencies during tests.
You got /4 concepts.