Related to this [question][1], I am trying to mock firestore when doing unit tests.
The code I am trying to mock looks like this:
const firestore = admin.firestore();
const users = await firestore.collection('users').get();
And my attempt to mock it looks like this:
const firestoreStub = sinon.stub();
Object.defineProperty(admin, 'firestore', {
get: () => {
return {
collection: (path) => Promise.resolve({mocka: 'user'})
}
}
});
However it does not work.
I have created a repo (a clone of the official functions repo), to give the entire example here if it helps.
With the help from Mark, I got this working:
sinon.stub(admin, 'firestore')
.get(() => {
return function() {
return {
collection: (path) => {
return {
get: () => [{user: 'mock-user-1'}, {user: 'mock-user-2'}]
}
}
}
}
});
It looks crazy - so if anyone knows a better solution, let me know!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With