I have a service that acts as a data-store. In it's constructor, it attempts to "hydrate" the data-set from the device's storage (using Ionic and it's Storage
service):
@Injectable()
export class SimpleDataStore {
private _data: BehaviorSubject<any> = new BehaviorSubject<any>(undefined);
public data: Observable<any> = this._data.asObservable();
constructor(private _http: HttpClient, private _storage) {
this.initializeData();
}
private initializeData(): void {
this._storage.get("dataKey")
.then(data => this._data.next(data))
.catch(() => this._data.next([]);
}
}
I know how to write async tests with Jasmine, and how to access private members/methods, as well as knowing to need to check _data.getValue()
for my desired result -- but my issue is not knowing how to test:
- The constructor, and/or;
initializeData
so that it waits for the Promise to finish, since no Promise is being returned in the method.
Thanks for any and all help!