Test implementation

In the previous section we created our DataSource and, so far, our DataSource consists of just an RxJS subject where we can push and listen to data. However, our data source could be a database, and for this reason for our tests we will always use a mock DataSource. So, let's implement our mock DataSource; inside the tests folder create a file called mock_datasource_factory.js, and paste in the following code:

let Rx = require('rx'); module.exports = function(){     let messagesSubjectMock = new Rx.Subject();     return{         push(data){             messagesSubjectMock.onNext(data);         },         get(){             return messagesSubjectMock;         }     }; }; 

In this code we export a function that, when executed, creates a Subject and returns an object containing ...

Get Mastering Reactive JavaScript now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.