I have this error:
'Unhandled Promise rejection:', 'Cannot read properties of undefined (reading 'then')', '; Zone:', 'ProxyZone', '; Task:', 'jasmine.onComplete', '; Value:', TypeError: Cannot read properties of undefined (reading 'then')
TypeError: Cannot read properties of undefined (reading 'then')
This is my .ts
file:
getPillars = async (): Promise<void> => {
if (localStorage.getItem('pillars')) {
this.pillars = JSON.parse(localStorage.getItem('pillars'));
return;
}
let items = await this.api.send('Categories', 'get', filter ? { filter: filter } : {}).then((res: { data: any[], count: number }) => {
return res.data.map(el => {
return { id: el.id, name: el.name, type: 'Categories' }
});
});
localStorage.setItem('pillars', JSON.stringify(items));
this.pillars = items;
}
And my test file:
describe('getPillars()', () => {
it('Should validate the session success', () => {
let spy1 = spyOn(apiService, 'send').and.returnValue(Promise.resolve(of('pillars')));
component.getPillars();
expect(spy1).toHaveBeenCalled();
});
});