angular-2-local-storage icon indicating copy to clipboard operation
angular-2-local-storage copied to clipboard

Creating a unit test that is using LocalStorageService

Open jostendorf opened this issue 8 years ago • 1 comments

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(); }));

jostendorf avatar Apr 10 '17 15:04 jostendorf

You want to mock out the service, not import its module

TestBed.configureTestingModule({
    providers: [
        { provide: LocalStorageService, useClass: MyMockStorageService },
    ]
});

Lightw3ight avatar Apr 12 '17 02:04 Lightw3ight