-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for onSnapshot #63
Comments
Thanks for pointing this out. It's not an API i've used. Digging into firestore's docs, it looks like it's a bit more complicated than the get call on a collection. 🤔 That seems a little inconsistent with some of their documented use-cases db.collection("cities").doc("SF")
.onSnapshot({
// Listen for document metadata changes
includeMetadataChanges: true
}, (doc) => {
// ...
}); Or db.collection("cities").where("state", "==", "CA")
.onSnapshot((querySnapshot) => {
var cities = [];
querySnapshot.forEach((doc) => {
cities.push(doc.data().name);
});
console.log("Current cities in CA: ", cities.join(", "));
}); Sometimes they refer to the object returned as a I'm assuming that it depends on whether you are fetching one versus multiple records. We should be able to get this to work with our current This was mostly me thinking out loud, but all this is to say that I will try to build this out but it seems to be a bit more complicated than just returning the same results as Any tips are welcome |
Thanks for taking a look!
Like the |
@HauptmannEck Can you see if your tests pass with #65 in your repo? |
@sbatson5 The tests I had built now work with that branch, and I get the expected output. |
Versions 0.8.0 was released with this update! |
Summary
Firestore has
.onSnapshot()
which is an alternative to.get()
on a collection. It is used to get realtime updates from the DB. This is currently not handled by this mock.Basic example
Motivation
My code uses quite a few of these to sync my UI with the DB, so to test them I need to be able to mock them and this library is the best option to mock Firebase.
To mock this we should be able to use the same logic as the
.get()
instead of as a Promise returning the query results as a function callback.The text was updated successfully, but these errors were encountered: