Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues during testing #122

Open
VamsiDevalla opened this issue Nov 25, 2019 · 3 comments
Open

Issues during testing #122

VamsiDevalla opened this issue Nov 25, 2019 · 3 comments

Comments

@VamsiDevalla
Copy link

Versions (please complete the following information):

  • NgxWebstorage: [e.g. 4.0.1]
  • Angular: [e.g. 8.2.14]

Describe the bug
I have updated my application to angular 8 from 5. Everything is good from the application side but the unit tests are failing saying Can't resolve all parameters for LocalStorageService: (?). at syntaxError (http://localhost:9876/_karma_webpack_/node_modules/@angular/compiler/fesm2015/compiler.js:2175:1).

My test file looks like this:
`import { TestBed, inject} from '@angular/core/testing';
import { LocalStorageService} from 'ngx-webstorage';
import { ThemeService } from './theme.service';
import { HttpTestingController, HttpClientTestingModule } from '@angular/common/http/testing';

const currentUser = require('../../../assets/data/currentUser.json');
describe('ThemeService', () => {
let httpMock: HttpTestingController;
let storage: LocalStorageService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpClientTestingModule,
],
providers: [
LocalStorageService,
ThemeService
]
});
storage = TestBed.get(LocalStorageService);
httpMock = TestBed.get(HttpTestingController);
});

beforeEach(() => {
storage.store('currentuser', currentUser);
});

it('should be created', inject([ThemeService], (service: ThemeService) => {
expect(service).toBeTruthy();
}));
});`

To Reproduce
Steps to reproduce the behavior:

  1. Write a test file 'using localStorageService'
  2. Run the tests
  3. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@rolfed
Copy link

rolfed commented Jan 30, 2020

I'm running into the same issue. Is there a solution to this problem?

@neilgrewal
Copy link

Any updates on this? Running into the issue with SessionStorageService

@lePhilissimo
Copy link

lePhilissimo commented Dec 1, 2020

I was able to get around this by:

  1. creating a mock object that implements the StorageService interface.
  2. configuring my provider to use the mocked object.
    Definitely not an ideal long term solution, but it got the tests passing again.

// Mock LocalStorageService
const mockStore = {};
const localStorageMock: StorageService = {
store: (key: string, value: string) => {
mockStore[key] = ${value};
},
retrieve: (key: string): string => {
return key in mockStore ? mockStore[key] : null;
},
clear: (key: string) => {
delete mockStore[key];
},
getStrategyName(): string {
return 'Local';
},
observe(key: string): Observable {
return EMPTY;
}
};

And then

beforeEach(() => {
TestBed.configureTestingModule({
providers: [
{provide: LocalStorageService, useValue: localStorageMock}
],
}); ....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants