Skip to content

Commit 27e7f8f

Browse files
committed
onSnapshot should call immediatly and then after data changes.
1 parent 65a9ddf commit 27e7f8f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/firestore-query.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ MockFirestoreQuery.prototype.onSnapshot = function (optionsOrObserverOrOnNext, o
170170
onError(err);
171171
}
172172
};
173+
174+
// onSnapshot should always return when initially called, then
175+
// every time data changes.
176+
onSnapshot();
173177
var unsubscribe = this.queue.onPostFlush(onSnapshot);
174178

175179
// return the unsubscribe function

test/unit/firestore-collection.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,16 @@ describe('MockFirestoreCollection', function () {
406406
it('Calls onError if error', function (done) {
407407
var error = new Error("An error occured.");
408408
collection.errs.onSnapshot = error;
409+
var callCount = 0;
409410
collection.onSnapshot(function(snap) {
410411
throw new Error("This should not be called.");
411412
}, function(err) {
413+
// onSnapshot always returns when first called and then
414+
// after data changes so we get 2 calls here.
415+
if (callCount == 0) {
416+
callCount++;
417+
return;
418+
}
412419
expect(err).to.equal(error);
413420
done();
414421
});

0 commit comments

Comments
 (0)