Closed lyubomir-bozhinov closed 5 years ago
Hi @MasterRennor , did you try to import NgxWebstorage in your testing module instead of declaring the services you need? As you can see here LocalStorageService & SessionStorageService need some extra inner services to run and with your current method they can't access them.
Here is an example of how to test the library (with a mock but it's not required).
regards,
@PillowPillow, thanks for you help! I'll try out your suggestions soon (and the second is sure to work) - but you can go ahead and close the issue.
I'm also getting this error when writing tests that include SessionStorageService
or LocalStorageService
as a provider. Importing NgxWebstorageModule.forRoot()
doesn't solve the issue for me in our failed tests.
Is there a way to get the tests working without mocking the internal state of the ngx-webstorage library?
@nexaddo, in most cases, importing NgxWebstorageModule.forRoot()
and removing the imported SessionStorageService
and LocalStorageService
fixes the issue. In several of my specs I had to use the mock approach. Just my two cents.
Hi @nexaddo ,
as @MasterRennor said, you shouldn't have to declare SessionStorageService
& LocalStorageService
in the providers section.
Import NgxWebstorageModule.forRoot()
and the services should be available without mocking anything.
@PillowPillow, apologies, if this has been solved in another ticket - I looked through them but couldn't find an answer.
Versions (please complete the following information):
Describe the bug I cannot create tests for components which import my project's StorageService (which internally imports LocalStorageService and SessionStorageService). Angular dependency injection needs them to be imported into the spec file or else it throws a 'missing providers' error. However, I end up with the following error when I do import them:
Example code:
This looks like quite a common use case to me, and maybe I'm missing something. Any help would be appreciated.