Angular Jasmine中的模拟Firestore文档
我已经为使用AngularFirestore的Ionic 4应用程序创建了单元测试,但是我没有成功地模拟firestore,有人知道如何模拟它吗 我已经试过了一个Angular Jasmine中的模拟Firestore文档,angular,firebase,jasmine,google-cloud-firestore,ionic4,Angular,Firebase,Jasmine,Google Cloud Firestore,Ionic4,我已经为使用AngularFirestore的Ionic 4应用程序创建了单元测试,但是我没有成功地模拟firestore,有人知道如何模拟它吗 我已经试过了一个spyOn(firestore.doc.prototype,'set') 但它返回此错误:set()方法不存在 [...] angularFirestoreStub = { doc() { return { set() { return Promise.resolve(); },
spyOn(firestore.doc.prototype,'set')
但它返回此错误:set()方法不存在
[...]
angularFirestoreStub = {
doc() {
return {
set() {
return Promise.resolve();
},
};
},
};
TestBed.configureTestingModule({
providers: [
UserService,
{ provide: AngularFireAuth, useValue: angularFireAuthStub },
{ provide: AngularFirestore, useValue: angularFirestoreStub }
],
}).compileComponents();
beforeEach(() => {
service = TestBed.get(UserService);
fireAuth = TestBed.get(AngularFireAuth);
firestore = TestBed.get(AngularFirestore);
});
[...]
it('deve salvar um perfil de usuário no Firestore', () => {
spyOn(firestore, 'doc').and.callThrough();
spyOn(firestore.doc.prototype, 'set');
service.createProfile('Wk4CvT5WpPPaQBgDTiPbY3MwED52', 'userName', 'userLastName')
.then(() => {
expect(firestore.doc).toHaveBeenCalledWith('users/Wk4CvT5WpPPaQBgDTiPbY3MwED52');
expect(angularFireAuthStub.doc.set).toHaveBeenCalledWith({
firstName: 'userName', lastName: 'userLastName'
});
});
});
我希望有人能帮我