How to test Observables

The ultimate guide — never again be confused on how to test Observables

Kevin Kreuzer
Angular In Depth

--

AngularInDepth is moving away from Medium. More recent articles are hosted on the new platform inDepth.dev. Thanks for being part of indepth movement!

Reactive Programming is the new way of handling asynchronous code. And it is super powerful!

If you came across this blog post, I assume that you already wrote some lines of reactive code with RxJS if not a thousand. So I don’t have to tell you how it works and how cool it is. 😎

I guess we are all on the same page — writing productive code with RxJS is powerful and makes a lot of fun. But what about testing?

What we’re going to learn 👨‍🎓

In this blog post, we are going to see the two different strategies on how to test an Observable.

The “subscribe and assert pattern” and “marble testing”.

We will apply those strategies in different scenarios to see their advantages and downsides. The comparison of those strategies in different situations leads us to a clear picture of how to test Observables.

Let’s start with the “subscribe and assert” pattern.

The Subscribe and assert pattern

--

--

Kevin Kreuzer
Angular In Depth

Passionate freelance frontend engineer. ❤️ Always eager to learn, share and expand knowledge.