soumak77 / firebase-mock

Firebase mock library for writing unit tests
https://soumak77.github.io/firebase-mock
349 stars 97 forks source link

Issue 81 onsnapshot #130

Open BrianChapman opened 5 years ago

BrianChapman commented 5 years ago

Implements onSnapshot. See https://github.com/soumak77/firebase-mock/issues/81

derekparker commented 5 years ago

This is great, I'm glad I found this because I really needed this functionality in tests, however in it's current state I don't think it'll quite work yet.

The functionality missing (or not quite working) is that:

  1. the first time calling onShapshot it should return the current state of the document / collection, not just when something changes.
  2. When chaining this off of a .where(...) it doesn't seem to work at all.

I think 2 is more related to a fundamental issue with this mocking library in that where() seems to resolve immediately, whereas in the real library it returns a lazy ref that must be resolved with get().

BrianChapman commented 5 years ago

@derekparker I updated this to return both immediately and when something changes. I'm not sure then where operator is fully implemented.

Venryx commented 4 years ago

These changes work well in my project.

Is there a reason this PR hasn't been able to be merged yet?

EDIT: Nevermind, I did notice an issue with the code: the onSnapshot callback sometimes wasn't called with the initial contents (if value was null at the time, or if called on a dec-ref instead of a query).

Created a new pull-request which resolves those issues: https://github.com/soumak77/firebase-mock/pull/158