I'm receiving the following error when running my unit tests:
Error: StaticInjectorError(DynamicTestModule)[BlogService -> Store]:
StaticInjectorError(Platform: core)[BlogService -> Store]:
NullInjectorError: No provider for Store!
Here is the code in my test file:
import { TestBed, inject } from '@angular/core/testing';
import { BlogService } from './blog.service';
describe('BlogService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [BlogService]
});
});
it('should be created', inject([BlogService], (service: BlogService) => {
expect(service).toBeTruthy();
}));
});
I'm not sure why this error is occuring. I thought the 'inject' call instantiates the service.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With