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