Search⌘ K
AI Features

Naive Testing Approach

Explore how to test lazy RxJS Observables by subscribing within Mocha unit tests, using the done() callback for asynchronous completion. Understand the challenges of testing Observables that emit multiple values and why simple approaches fall short. This lesson lays the foundation for more advanced testing methods like Marble testing.

We'll cover the following...

So far, you have learned that Observables are lazy; they start emitting values only when an Observer is subscribed to it. So, how do you test a lazy Observable? The answer is simple: you simply subscribe to the Observable and expect the right values. Let’s analyze the following code:

var observable$ = getObservableForTest()
it('Testing a lazy observable', () => {
  
   observable$.subscribe(callbackFunction)

})

First of all, this is a simple unit test using Mocha.js ...