jeudi 3 décembre 2015

Firebase unit test issue when getting object by uid from Firebase

Firebase unit test issue when getting object by uid from Firebase.

The cod eworks fine, its just the unit test I'm doing wrong.

The error I'm getting in git bash is: "cannot read property 'orderByChild' of undefined".

How do I test this code properly?

This is my code I'm testing - test for function name "getUserProfileByUid":

 export class FirebaseService {
   refProfiles: Firebase;

   constructor() {   
     this.refProfiles = new Firebase("http://ift.tt/1XHbmnu"); 
   }

   public getUserProfileByUid(uid: number): any{
       var profile = this.refProfiles.child('profiles');
       var query = profile.orderByChild('uid').equalTo(uid);

       query.once('value', (snap) => {   
         var key = Object.keys(snap.val());  
         var response = snap.val()[key.toString()];

         return response;
       });
   }
 }

This is my test:

 import { it, iit, describe, expect, inject, injectAsync, beforeEachProviders, fakeAsync, tick } from 'angular2/testing';
 import { FirebaseService } from '../app/firebase-service';

 describe('Firebase Service Calls', () => {

     it('get user profile by uid from Firebase', () => {
         let refProfiles = new Firebase("http://ift.tt/1XHbmnu");
         let service = new FirebaseService();
         let uid = 123;

         spyOn(service.refProfiles, 'child');
         service.getUserProfileByUid(uid);

         expect(service.refProfiles.child).toHaveBeenCalled();
     })

 });

This is the git bash error I get:

enter image description here

Thank you.

Aucun commentaire:

Enregistrer un commentaire