import { TestBed, async, inject } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { MyService } from './services/my-service.service';
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [AppComponent],
providers: [MyService]
}).compileComponents();
}));
it('should create the app', async(inject([MyService], (myService: MyService) => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
})));
});
Fixes:
StaticInjectorError(Platform: core)[MyComponent -> MyService]:
NullInjectorError: No provider for MyService!
Error: StaticInjectorError(DynamicTestModule)[MyComponent -> MyService]:
References: StackOverflow