We have implemented some custom form control components with decorators as follows:
@Component({
selector: 'value-selector',
templateUrl: './selector.component.html',
styleUrls: ['./selector.component.scss'],
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => ValueSelectorComponent),
multi: true
}
]
})
During the update of certain dependencies, particularly babel, we had to introduce the forwardRef. This caused our provider to change from:
useExisting: ValueSelectorComponent,
to:
useExisting: forwardRef(() => ValueSelectorComponent),
The JEST spec tests are set up to create a new instance using an instantiate method that is executed in the beforeEach block:
function instantiate({
eventTypeService = {},
translationService = {}
}): ValueSelectorComponent {
return new ValueSelectorComponent(
eventTypeService as EventTypeService,
translationService as TranslateService
);
}
describe(ValueSelectorComponent.name, () => {
let component: ValueSelectorComponent;
// abbreviated for clarity
beforeEach(() => {
mockTranslateGet = jest.fn().mockReturnValue(of());
mockTranslationService = {
get: mockTranslateGet
} as unknown as TranslateService;
getAllSpy = jest.fn();
mockEventTypeService = {
getAll: getAllSpy
} as unknown as EventTypeService;
// abbreviated for clarity
component = instantiate({
eventTypeService: mockEventTypeService,
translationService: mockTranslationService
});
});
However, I am facing challenges in achieving code coverage for () and ValueSelectorComponent within the useExisting
. Our test suite uses JEST, and all solutions discovered so far involve TestBed, which we do not utilize. Is there a way to ensure coverage for that particular line?