NullInjectorError: No provider for Store
You can use the ngrx mock store:
import { provideMockStore } from '@ngrx/store/testing';
beforeEach(() => {
TestBed.configureTestingModule({
providers: [provideMockStore({})],
});
});
You can define a specific state and pass it as method parameter.
if your service is referencing an ngrx store then you need to import the ngrx modules. I am making an assumption right now that you are doing that in your AppModule. You need to duplicate that in your TestBed module. I generally create a test ngrx module that does all that and then I can just import that in any spec file that references Store
As stated here
Add following to the specs.ts file:
// Add the import the module from the package
import { StoreModule } from '@ngrx/store';
// Add the imported module to the imports array in beforeEach
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
StoreModule.provideStore({})
],
declarations: [
// The component that's being tested
]
})
.compileComponents();
}));
And if you get error Property 'provideStore' does not exist on type 'typeof StoreModule
use forRoot instead
of provideStore
.
Also look here and here is similar question here.
Cheers!