I got the following error while I ran ng test
:
Error: StaticInjectorError(DynamicTestModule)[Component -> Store]:
StaticInjectorError(Platform: core)[Component -> Store]:
NullInjectorError: No provider for Store! at NullInjector.push../node_modules @angular/core/fesm5/core.js.NullInjector.get
To fix this error you need to push StoreModule.forRoot({})
into imports
array in object that passed into configureTestingModule
method. You need to do this in the test file of the component that caused this error.
Here is an example of fix:
import { Store, StoreModule } from '@ngrx/store';
describe('Component', () => {
let component: Component;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [Component],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [StoreModule.forRoot({})]
}).compileComponents();
store = TestBed.get(Store);
}));