...

/

Testing With Dependencies

Testing With Dependencies

Learn how to test code with dependencies using stubbing and spying.

In this lesson, we will look at a more advanced scenario for testing a component with dependencies.

In a real-world scenario, components are not usually as simple as AppComponent. They will almost certainly be dependent on one or more services. We have different ways of dealing with testing in such a situation. One thing is clear, though: if we are testing the component, then we should not test the service as well. So, when we set up such a test, the dependency should not be the real thing. There are different ways of dealing with that when it comes to unit testing; no solution is strictly better than another:

    ...