constructor(private a:dependencyA,private b:dependencyB,private c:dependencyC){
}
dependencyA could look like this:
export class dependencyA {
showPopup: boolean;
defaultProperties = {
showPopup: this.showPopup,
};
private propertiesSource = new BehaviorSubject(this.defaultProperties);
currentProperties = this.propertiesSource.asObservable();
}
In order to be able to unit test I will have to write stubs for each constructor dependencies along with dummy data or methods within each stub by hand to make it work.
Something like:
class dependencyAStub{
defaultProperties = {
showPopup: false,
};
private propertiesSource = new BehaviorSubject(this.defaultProperties);
currentProperties = this.propertiesSource.asObservable();
push(value){
this.propertiesSource.next(value);
}
}
and,
TestBed.configureTestingModule({
declarations: [ ComponentDetailsComponent ],
providers: [{ provide: dependencyA, useClass: dependencyAStub }],
providers: [{ provide: dependencyB, useClass: dependencyBStub }],
providers: [{ provide: dependencyC, useClass: dependencyCStub }],
})
Is there a better way to provide mock stubs for all the dependencies ? If there are 8 dependencies in the constructor of the component and each one has like 4-5 functions and properties. I will have to spend a lot of time writing stubs. It would be great if I could generate stubs etc automatically and may be specify specific values for one or more dependencies manually for testing.