Open dev-andremonteiro opened 3 years ago
I'm not sure it's the correct way to do it, but this is what I use:
test utils:
const firestoreDeleteChildren = ref => {
// Firestore recursive delete
Object.values(ref.children).forEach(child => {
firestoreDeleteChildren(child)
if (child.delete) {
child.delete()
}
})
exports.clearFirestore = () => {
const { firestore } = require('./pathToYourFirestoreInit')
// safe!
if (firestore.constructor.name === 'MockFirestore') {
console.log('Clearing MockFirestore')
firestoreDeleteChildren(firestore)
}
}
in tests:
const { clearFirestore } = './testUtils'
beforeEach(() => {
clearFirestore()
})
I have posted to this issue in the old repository, but it seems like we moved to this repository so I might as well post here, sorry about that I didn't know issues should be moved to this one.
I have been trying to reset my firestore database so my tests don't have remaining data from past tests, I have found some resources in the issue linked above but I can't seem to get the database reset even after making the reassignment of the firestore variable.
Maybe some of you know how to do this in version 2.3.2, do we have a function that makes this in the library ?