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, ...

Get Mastering Reactive JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.