Giter VIP home page Giter VIP logo

Comments (5)

sbatson5 avatar sbatson5 commented on June 19, 2024

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.

HauptmannEck avatar HauptmannEck commented on June 19, 2024

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.

sbatson5 avatar sbatson5 commented on June 19, 2024

@HauptmannEck Can you see if your tests pass with #65 in your repo?

from firestore-jest-mock.

HauptmannEck avatar HauptmannEck commented on June 19, 2024

@sbatson5 The tests I had built now work with that branch, and I get the expected output.

from firestore-jest-mock.

sbatson5 avatar sbatson5 commented on June 19, 2024

Versions 0.8.0 was released with this update!

from firestore-jest-mock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.