I have the same set up as this post https://stackoverflow.com/a/42462579/1818048
But i am unable to use the ServiceLoctor.inject.get in my Karama Jasmine tests - the injector is null
constructor() {
this.inject = ServiceLocator.injector.get(InjectionService);
this.configService = ServiceLocator.injector.get(ConfigService);
}
In the app.moudle module i declared the following so that it is globally available.
export class AppModule {
constructor(private injector: Injector) {
ServiceLocator.injector = this.injector;
}
}
Here is a snippet from my test setup
describe('MyButtonComponent', () => {
let component: MyButtonComponent;
let fixture: ComponentFixture<MyButtonComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ButtonComponent, MyButtonComponent],
providers: [SomeService,
{ provide: Router, useClass: RouterTestingModule },
{ provide: ServerService, useClass: GenericMock },
]
})
.overrideComponent(ResourceService, {
set: {
providers: [
{ provide: ConfigService, useClass: ConfigServiceMock }
]
}
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(MyButtonComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
Now when i run the test ServiceLocator.injector is null. How can i make Karma Jasmin set this in the parent or is this not possible?