I am adding unit tests in my Angular 7 app. I have 100 components to test, at least, and each one are failing because of the configuration: they need the declaration of each dependencies needed.
This is my component.spec.ts where is the configuration when I execute ng test
:
import { async, ComponentFixture, TestBed } from
'@angular/core/testing';
import { myComponent } from './mycomponent';
import { FontAwesomeModule } from '@fortawesome/angular-
fontawesome';
describe('myComponent', () => {
let component: myComponent;
let fixture: ComponentFixture<myComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ myComponent ],
imports: [
FontAwesomeModule
// + Others imports
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(myComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
In some components, I add providers. In some cases, I use a mockService. Everything I did, comes from angular docs.
Is there a way to configure easily or automatically unit tests (or end to end tests) with Angular, instead of to add every module needed manually?
I am using Angular 7, jasmine (3.3.1) and karma (4.0.0).