constructor(private a:dependencyA,private b:dependencyB,private c:dependencyC){
}
Here is an example of how dependencyA is structured:
export class dependencyA {
showPopup: boolean;
defaultProperties = {
showPopup: this.showPopup,
};
private propertiesSource = new BehaviorSubject(this.defaultProperties);
currentProperties = this.propertiesSource.asObservable();
}
When unit testing, I find myself manually creating stubs for each constructor dependency with mock data or methods. For instance:
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 }],
})
I hope there's a more efficient way to create mock stubs for all dependencies. With multiple dependencies in the component's constructor, and each having several functions and properties, it becomes time-consuming to manually generate stubs for each one. It would be beneficial if there was an automated process for generating stubs, while still allowing for manual specification of specific values for certain dependencies during testing.