lundi 30 décembre 2019

Testing rxjs pipe operator in constructor

I have class to handle the user/auth operations from firestore. The service works correctly but when I try to add test to the service if fails with the error TypeError: Cannot read property 'pipe' of undefined

This is my service

export class AuthService {
  user$: Observable<User>;

  constructor(private afAuth: AngularFireAuth, private afs: AngularFirestore) {
    this.user$ = this.afAuth.authState.pipe(
      switchMap(user => {
        if (user) {
          return this.afs.doc<User>(`user/${user.uid}`).valueChanges();
        } else {
          return of(null);
        }
      })
    );
  }
}

and this is part my spec file for that class

describe('AuthService', () => {
  beforeEach(() =>
    TestBed.configureTestingModule({
      providers: [
        { provide: AngularFireAuth, useValue: FireAutStub },
        { provide: AngularFirestore, useValue: FirestoreStub }
      ],
      imports: [AngularFireModule, AngularFireAuthModule]
    })
  );

  it('AuthService should be created', () => {
    const service: AuthService = TestBed.get(AuthService);
    expect(service).toBeTruthy();
  });
});

any ideas of why the testing is throwing TypeError: Cannot read property 'pipe' of undefined or do you have any suggestions to test it better o make the service more "testable"?

Aucun commentaire:

Enregistrer un commentaire