I'm just starting with Angular2 but I try to test every component I write.
When I write component tests I have to initialize TestBed so component under test have all its (transitive) dependencies resolved.
Now I can think of three approaches
- Import whole module containing the component under test - it should declare or import all the required dependencies
- Explicitly declare all dependencies in test code
- Mock all dependencies - so they do not have its own dependencies
I think first solution may cause problems when I need to mock things that are already declared in main module. The second require me to manually change all dependent tests when I try add any new dependency to component. I did not test the third one so I do not know if it is doable.
What is the best way to handle this?