Comments (5)
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.
https://firebase.google.com/docs/reference/js/firebase.firestore.CollectionReference#onsnapshot
🤔 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 doc
but other times as a QuerySnapshot
which is an instance of a QuerySnapShot object.
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 buildQuerySnapShot
helper (props to @AverageHelper for building it 🙌 ).
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 get
. I want to make sure we add support for the other things that a snapshot can do, in case someone else uses this and it doesn't work as expected.
Any tips are welcome
from firestore-jest-mock.
Thanks for taking a look!
Yeah I have not used the optional observer
or options
parameters of the onSnapshot
method, so I don't have much insight into them and have no idea how widly used they are. I have only used the basic pattern:
onSnapshot ( onNext : ( snapshot/doc : QuerySnapshot/Document < T > ) => void)
Like the .get().then(...)
pattern the onNext
callback returns a single doc
for DocumentReference.onSnapshot()
and QuerySnapshot
for the CollectionReference.onSnapshot()
from firestore-jest-mock.
@HauptmannEck Can you see if your tests pass with #65 in your repo?
from firestore-jest-mock.
@sbatson5 The tests I had built now work with that branch, and I get the expected output.
from firestore-jest-mock.
Versions 0.8.0 was released with this update!
from firestore-jest-mock.
Related Issues (20)
- Module firebase-admin not found, mocking skipped HOT 2
- Firestore instance in snapshot.ref go undefined after make a document query request to the database HOT 1
- QueryDocumentSnapshot that passed to trigger functions doesn't contain createTime element HOT 1
- Firebase Cloud Messaging HOT 2
- Is Firestore mock delete() not yet implemented? HOT 6
- How to test a trigger HOT 2
- Where query on nested fields HOT 6
- Firestore mock for DocumentReference.create() HOT 7
- Checking for mockUpdate within a datasnapshot forEach HOT 3
- React Native Support HOT 3
- include firebase/admin with 'import' instead of 'require' HOT 4
- Example of multiple tests with different database data? HOT 3
- Jest, `mockDoc` validate collection type (v0.18.0)
- Requires wrong package for firebase 9 HOT 4
- firestore and auth mocks not complete on firebase-admin HOT 1
- broken links for firebase doc references
- `set` without merge overrides _collections
- Transfer Repo HOT 9
- Is there a way to test multiple firestore states? HOT 1
- How to mock properly @react-native-firebase/firestore HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from firestore-jest-mock.