Within my component, I am utilizing two different helper classes as shown below:
import {HelperA} ...
import {HelperB} ...
...
@Component({..})
export class MyComponent implements OnInit {
helper: Helper;
constructor(private ref: ElementRef, private device: MyDeviceDetectionService) {}
ngOnInit() {
if (this.device.isMobile) {
this.helper = new HelperA(this.ref);
} else {
this.helper = new HelperB(this.ref);
}
}
}
I am aware that this setup makes unit testing challenging. How can I handle the injection of these helpers in a way that only one is needed based on the isMobile
condition being true or false?