How to marble test RxJS Subjects

How to bridge the gap between the timing of function calls and Observables

Kevin Kreuzer
6 min readDec 3, 2020

Asynchronous code is hard! It’s hard to write and to test.

RxJs has changed the way we think about asynchrony. Instead of using Promises, we nowadays deal with streams in the form of Observables or Subjects. RxJs provides us with many out of the box operators to create, merge, or transform streams.

But we do not only get great tools for runtime code, but we also get amazing tools to test streams.

Marble diagrams are a great way of modeling streams. They are used throughout many tutorials and can now also be used in tests to assert streams.

In case you never heard of marble testing I recommend you to checkout the following article.

Marble testing is great! Many people use it to test their Observables. But what about Subjects?

A pizza service 🍕

--

--

Kevin Kreuzer
Kevin Kreuzer

Written by Kevin Kreuzer

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

Responses (2)