O'Reilly logo

Hands-on Full Stack Development with Angular 5 and Firebase by Uttam Agarwal

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

Unit testing an Angular service

In this section, we unit test an Angular service and we write test cases for our user service. The steps for unit testing a service are the same as for our component. 

The first step in writing unit test cases is to analyze the dependent components, as we see user service is dependent on AngularFireDatabase and initializes the Firebase storage object:

constructor(private fireDb: AngularFireDatabase)

So we create a stub for this dependent object such as AngularFireDatabaseStub, which contains other dependent stubs such as AngularFireAppStub and AngularFireObjectStub object references and the object() method:

class AngularFireDatabaseStub {   app: AngularFireAppStub = new AngularFireAppStub;   angularFireObject

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