child-class component(BusinessRegistration)
export class BusinessRegistration extends BizAbstractRegistration {
constructor(protected readonly injector: Injector) {
super(injector);
}
other methods....
}
base class abstract with DI
export abstract class BizAbstractComponent implement BizActionHandler {
protected logger : NGXLogger;
protected anchorservice : AnchorService;
.....other services
protected constructor (protected readonly injector:Injector) {
this.logger = injector.get(NGXLogger);
this.anchorservice = injector.get(AnchorService);
.... so on
}
}
child class test case
describe('BusinessRegistration', () => {
Testbed.configureTestingModule({
declarations: [BusinessRegistration],
imports: [BusinessRegistrationModule],
providers: [{
provide: NGXLogger,
useValue: jasmine.createSpyObj('logger', ['debug']),
},
{
provide: AnchorService,
useValue: jasmine.createSpyObj('anchorService', ['scrollToTop']),
},
]
}).compileComponents().then(() => {
fixture = TestBed.inject < BusinessRegistration > (BusinessRegistration);
component = fixture.componentInsatance;
fixture.detectChanges();
})
describe('test for BusinessRegistration to be created', () => {
it('expect BusinessRegistration to be truthy', () = {
expect(component).toBeTruthy();
});
});
NullInjectionError: R3InjectorError(DynamicTestModule) [StoreFeatureModule ->ReducerManager->ReducerManager]
The test cases are failing with the above error.
I tried to create a concrete class and extend the abstract class and then mock the dependencies in that class and the instantiate that class too. but did not work .
Basically , I have a parent Abstract class for my component and it has dependencies injected in its constructor using 'injector.get()' . I want to write the unit test for my component.