我有一个类来处理来自Firestore的用户/身份验证操作。该服务正常运行,但是当我尝试向该服务添加测试时,如果失败并显示错误TypeError: Cannot read property 'pipe' of undefined
这是我的服务
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);
}
})
);
}
}
这是我针对该课程的规范文件的一部分
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();
});
});
关于为什么要进行测试TypeError: Cannot read property 'pipe' of undefined
的任何想法,或者您有什么建议可以更好地进行测试,以使服务更“可测试”?