DEV Community

Discussion on: RxJS 7 is released 🎉

Collapse
 
lyrod profile image
Lyrod

I don't understand the toPromise deprecation. You can't convert an observable to a promise?

It was helpful for unit tests

Collapse
 
vazsonyidl profile image
vazsonyidl

It depends on your test setup, without any other info it is hard to reply. :( Maybe you could give a try for lastValueFrom instead of toPromise as it is planned to replace that one-in-one.

Or if your setup was something like this one :

    this.items = await this.itemService
      .getItems()
      .toPromise()
Enter fullscreen mode Exit fullscreen mode

Now you can use this instead:

    const items$ = this.itemService.getItems();
    this.items = await lastValueFrom(items$);
Enter fullscreen mode Exit fullscreen mode

I hope I can help you, but reply if do not. :)

Collapse
 
lyrod profile image
Lyrod • Edited

This is exactly what I do in my tests! Thanks!