Comments (6)
That said, I actually intend to spend sometime helping this library evolve if possible, just won't have much time to do so for the next months haha
Some PR's and help would be great 😅
I love that others have found this library useful, but it's hard to keep up with it with my day job -- especially considering there are so many aspects to firestore I haven't used, so can't confidently write mocks/tests
from firestore-jest-mock.
You're right, there isn't currently support for that. I feel like this starts to get into the area of "how much behavior do we reproduce?" If we write code in this repo to allow for querying nested keys, then the tests we write against this mock are really only testing this repo and not necessarily firestore or your code.
I just worry we'll spend a lot of time writing a ton of complicated code and users won't actually be testing anything useful
from firestore-jest-mock.
You're right, there isn't currently support for that. I feel like this starts to get into the area of "how much behavior do we reproduce?" If we write code in this repo to allow for querying nested keys, then the tests we write against this mock are really only testing this repo and not necessarily firestore or your code.
I just worry we'll spend a lot of time writing a ton of complicated code and users won't actually be testing anything useful
Interesting, we are pretty much able to test all the Firestore related methods we have, but the ones that use nested fields, we are testing more than simple logic indeed but this library has been quite helpful for us.
One example of changing the code and test structure to make it testable is that this library doesn't simulate the triggers happening either, in that case, what we did was move the trigger logic to specific methods we could test in isolation, in that sense, I agree that adding triggers support could not be as necessary, this case is a bit diff as it is a query clause that is supported Firestore natively so I feel it would be good to have it as well, just like we have collection groups, IN queries and so on.
from firestore-jest-mock.
I can certainly be convinced (have been in the past with other functions here). I guess my question is, what would your test look like. Is it something like:
db.collection('animals').where('species.type', '==', 'mammal').then((snapshot => {
snapshot.forEach(doc => expect(doc.data().type).toEqual('mammal'));
});
We query for mammals in our nested field and we assert that all the ones returned are of the type: mammal. In my opinion, what is written above isn't a useful test, since it really only tests that firestore-jest-mock
wrote a where
function that properly filters nested fields. At a quick glance, it looks like a good test, but it hasn't really tested anything. What's important is that you interfaced with the firestore API properly. i.e. expect(mockWhere).toHaveBeenCalledWith('species.type', '==', 'mammal')
-- what it returns is irrelevant because you'd never question what firestore returns.
But I admit there are probably use-cases I'm not thinking of, so I'm curious to here your thoughts. I just don't want to get into feature parody hell, as it would take too much maintenance time on this library as Google inevitably updates their APIs and behaviors.
from firestore-jest-mock.
We are actually doing it at a bit higher level, we have a few functions that handle complex logic internally, we have extracted those into specific helper methods as we could, for example, one method gets all the documents for a user that could conflict/overlap in time with one specific event, this helper takes the document to be tested and a user UID, it will fetch all the events for that user in between a date range.
In this specific case, we extracted the internals of this method even more and passed a mocked list of items so we could unit test it, but would also be good to test the parent method that has this part as one of its internals without having to do it via the emulator, this library saves us a lot of time as we can mock almost the whole Firestore stack!
That said, I actually intend to spend sometime helping this library evolve if possible, just won't have much time to do so for the next months haha
from firestore-jest-mock.
Just want to mention here this would be really useful, since we're storing data in a more object vs array approach.
from firestore-jest-mock.
Related Issues (20)
- Error in @google-cloud/firestore compatibility example HOT 4
- 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
- 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 HOT 1
- Transfer Repo HOT 9
- Is there a way to test multiple firestore states? HOT 1
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.