forked from soumak77/firebase-mock
-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clear, reset or erase Firestore database in each test #73
Comments
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()
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 ?
The text was updated successfully, but these errors were encountered: