Testing RxJS observables with Promise – the simplest way
When testing RxJS code, you typically want to verify that your
observables emit the expected values in response to certain actions or events.
See how you can cover those cases using async/await approach.
When a observable emits many values writing a testing scenario can be difficult.
One of the official solution is to use marble diagrams
but is may be overkill for simple scenarios.
Better idea can be transforming a RxJS stream into promise and using async/await keywords.
Read case scenario
Imagine a situation where you have written a store to manage tasks in your application.
Let us write a test where we will try to check if our class correctly stores added tasks.
To do this we will use promises.
firstValueFrom function converts observable to promise by returning the first emitted value.
Do you like the content?
Your support helps me continue my work. Please consider making a donation.
Donations are accepted through PayPal or Stripe. You do not need a account to donate. All major credit cards are
accepted.