-
Notifications
You must be signed in to change notification settings - Fork 1
Description
First I would like to thank you Gustavo for all the hard work you have put into mocking Firebase.
I have been attempting to build out proper unit test when using Angular Fire and your mock of Firebase has been instrumental in building out proper mocks.
I am running into an issue with your mock of Firestore though. That is that it is only sending me the added docs but not removed or modified.
This is the section of code that I am getting stuck and and not getting past the short circuit.
mockbase/firestore/query-snapshot.ts
Lines 29 to 37 in e271ba2
| if (this === this.query.lastSnapshot || !this.query.lastSnapshot) { | |
| // Short circuit: this is the first snapshot, so all items were added. | |
| return this.docs.map((doc, newIndex) => ({ | |
| type: "added", | |
| oldIndex: -1, | |
| newIndex, | |
| doc, | |
| })); | |
| } |
This is where the lastSnapshot seems like it should be set to prevent that short circuit
Lines 41 to 55 in e271ba2
| public async emitChange() { | |
| if (!this.emitter.hasListeners(QUERY_SNAPSHOT_NEXT_EVENT)) { | |
| return; | |
| } | |
| // TODO: this emits even if there wasn't an actual change with the current filters | |
| const snapshot = await this.get(); | |
| this.lastSnapshot = snapshot; | |
| this.emitter.emit(QUERY_SNAPSHOT_NEXT_EVENT, [snapshot]); | |
| } | |
| setNoInitialSnapshot(): this { | |
| this.noInitialSnapshot = true; | |
| return this; | |
| } |
Code I am using
const subject = new Subject();
this.app
.firestore()
.collection(path)
.onSnapshot({
next: (collection) => {
subject.next(
collection.docChanges().map(({ type, doc }) => ({ type, payload: { doc } }))
);
},
error: (err) => subject.error(err),
complete: () => subject.complete(),
});
subject.subscribe(console.log);I have played around with it for a bit but can't seem to figure out the exact cause. My guess is either (a) lastSnapshot isn't being set OR (b) the current snapshot and lastSnapshot are always in sync, or at least at the time when docChanges() runs from within a onSnapshot()
Again thank you so much for your work. Let me know if you need any more information or have any work arounds.