Error No Provider for Store Ng Test

angular typescript ngrx

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(() => {
      declarations: [Component],
      schemas: [CUSTOM_ELEMENTS_SCHEMA],
      imports: [StoreModule.forRoot({})]

    store = TestBed.get(Store);
comments powered by Disqus