My decisions are based on @kampsj's solution, but I think it is cleaner.
TestBed
create a dynamic module. So we can use the module with entryComponents
(nothing new). My difference is that I do not create testModule , I just import the module in which this component belongs , and is cleaner because you do not need to add everything else (service, other components, etc. ... ). This means that if ng serve
works, then ng test
should (at least from the point of view of the creation component).
Suppose we have the following structure:
app ├--- app.module.ts ├--- app.component.ts ├--- ... ├--- SomeModule2 | ├--- somemodule2.module.ts | ├--- componentThatCreateDynamicsComponents | ├--- componentThatCreateDynamicsComponents.component.ts | ├--- componentThatCreateDynamicsComponents.html | ├--- componentThatCreateDynamicsComponents.component.spec.ts | ├--- someCOmponent | ├--- someCOmponent.component.ts | ├--- someCOmponent.html | ├--- someCOmponent.component.spec.ts
TestBed
componentThatCreateDynamicsComponents.component.spec.ts should import somemodule2
from somemodule2.module.ts. If you do not divide the project into modules, there must be a unique module that you have.
It is true that you will have a component that you do not use in this test, but that does not matter, because it is just a test. And you get the flexibility to change the test module.
source share