I'm trying to test the emptyBasket method and since I upgraded the deprecated toPromise() to lastValueFrom() (rxjs 7.1.0) and I only get the error:
message:'no elements in sequence'
name:'EmptyError'
Method under test:
emptyBasket(): Promise<void> {
return lastValueFrom(this.shoppingClient.emptyBasket()).then(() => this.store.dispatch(new EmptyBasket()));
}
Test:
it('should call emptyBasket on shoppingClient', (done) => {
mockStore.dispatch = jest.fn();
shoppingClientMock.prototype.emptyBasket = jest.fn().mockReturnValue(of());
service.emptyBasket().then(() => {
expect(shoppingClientMock.prototype.emptyBasket).toHaveBeenCalledTimes(1);
expect(mockStore.dispatch).toHaveBeenCalledTimes(1);
expect(mockStore.dispatch).toHaveBeenCalledWith(new EmptyBasket());
done();
},
(err) => {
console.log('error', err)
done();
}
);
});
Does anybody know how to workaround this problem?
Many thanks!