I am trying to write unit test for the following function
public loadValues(): Promise<any> {
return this._http.get(this.url)
.toPromise()
.then((values: any) => {
this.values = values;
})
}
This function is called by the APP_INITIALIZER and thats the reason it is returning a promise instead of observable. I did not find any article to test toPromise, any help will be appreciated.
I have the following test written for it
it('should return app values', async () => {
const mockValues = {test: 123};
spyOn(httpClient, 'get').and.returnValue(of(mockValues)).and.callThrough();
await service.loadValues();
expect(service.values).toEqual(mockValues);
const req = httpMock.expectOne(TEST_URL);
expect(req.request.method).toBe('GET');
});