I have an AppConfigService that loads an object from a JSON file into a static settings variable that is part of the service. Various components and/or services throughout the application reference the object with AppConfigService.settings., with a simple reference (no injection). How can I test a service that is referencing this kind of construction?
For example
@Injectable()
export class SomeService {
someVariable;
constructor() {
// I can't get the test to not give me a TypeError: Cannot read property 'someSettingsVariable' of undefined on this line
this.someVariable = AppConfigService.settings.someSettingsVariable;
}
}
I have two projects, one using Jest and another Jasmine/Karma and I need to figure out the pattern of how to get the test to work in this construction.
I have tried things like:
const spy = spyOnProperty(SomeService, 'someVariable')
.and.returnValue('someValue');
Any assistance from testing gurus would be appreciated.
Aucun commentaire:
Enregistrer un commentaire