Learning about the marble testing pattern
Marble diagrams are very useful for visualizing observable execution. We learned about marble diagrams in Chapter 1, The Power of the Reactive Paradigm, and we've used them in almost all the reactive patterns we've implemented in this book. At this point, I think you are very familiar with marble diagrams. They are simple to understand and delightful to read. So, why not also use them in code? What you will be surprised to know is that RxJS introduced marble testing as an intuitive and clean way to test observables.
Let's discover what marble testing is about. We will start by explaining the syntax in the next section and then learn how we can write marble tests in our code.
Understanding the syntax
To understand the syntax, we should know about the following semantics:
This is the basic syntax. Let's look at some examples to practice the syntax:
—--
: This represents...