angular-2-local-storage
angular-2-local-storage copied to clipboard
Creating a unit test that is using LocalStorageService
I am having an issue creating/running a unit test using angular-2-local-storage. I believe I have the test setup correctly, but getting this error. Not sure what to do next.
Error: No provider for LOCAL_STORAGE_SERVICE_CONFIG!
Setting up the test: import { LocalStorageModule, LocalStorageService } from 'angular-2-local-storage';
beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ LocalStorageModule.withConfig({ prefix: 'bpf', // storageType: 'localStorage' storageType: 'sessionStorage' }) ], declarations: [ DisabilityQuoteComponent ], providers: [LocalStorageService, { provide: WorkInProgressService, useValue: MockWorkInProgressService } ] }) .compileComponents(); }));
You want to mock out the service, not import its module
TestBed.configureTestingModule({
providers: [
{ provide: LocalStorageService, useClass: MyMockStorageService },
]
});