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

Service implementation

Now that we have the test for our service we are ready to create the implementation of this service. To do this, change the current implementation of the sendMessage service in the services.js file to the following:

sendMessage(payload){       if(payload && payload.content && payload.from){         dataSource.push({           from: payload.from,           to:payload.to,           content: payload.content         });       }     } 

The implementation of our service is simple: it just verifies whether the payload exists and whether it has content and from properties; if our argument is valid all we have to do is to push the message to our datasource.

Now we can run our test again using the same command and see the results:

Now our services are passing as expected, so we ...

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