O'Reilly logo

Mastering Reactive JavaScript by Erich de Souza Oliveira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testing applications using RxJS

When developing using functional reactive programming, you are separating the source of your data from the actions taken when that data is available. This can help test your application, as you can mock your observables to test your observers and keep it independent of your real data source.

To demonstrate this behavior, imagine a program that fetches a web page and extracts all the numbers on that page. We can implement this using regular expressions:

var Rx = require('rx'); var request = require('request-promise'); var parser = {      getPageObservable: (url)=>Rx.Observable.fromPromise(request(url)),      parseContentObservable: (observable)=>observable           .flatMap((str)=>Rx.Observable           .fromArray(  str.replace( /\D+/g, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required