Writing a Real-world Test
Explore how to write real-world tests for RxJS Observables by leveraging Schedulers and virtual time. Understand how to use TestScheduler to simulate asynchronous events, buffer data, and validate outputs without long waits. This lesson helps you grasp advanced testing techniques crucial for managing concurrency and timing in reactive programming.
We'll cover the following...
There’s no better way to understand how to bend time using virtual time than to write a test for a time-sensitive task in the real world. Let’s recover an Observable from the earthquake viewer we made earlier.
To make the code more testable, let’s encapsulate the Observable in a function that takes a Scheduler we use in the bufferWithTime operator. It’s always a good idea to parameterize Schedulers in Observables that will be tested.
Let’s also simplify the code by taking some steps out, but retaining the essence of it. This code takes an Observable of JSON objects that contain a properties property, buffers them into batches released every 500 milliseconds, and filters the batches that arrive empty.
We want to verify that this code works, but ...