-
Notifications
You must be signed in to change notification settings - Fork 934
v9 collection()
not working with @firebase/rules-unit-testing "Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore"
#6080
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
Comments
Can you run |
|
I ran into the same problem simply trying to getDoc a document reference in a v9 unit test.
Is there any workaround for this? |
I am facing the same error: |
I'm seeing the same error with nextjs but only on the build step or server render. It loose like the firestore is created but is not an instanceof Firestore...
Overriding the prototype makes it work...
Suggesting getFirestore() and doc() are not using the same Firestore? |
@acorcutt Are you using |
@yuchenshi No this is in a nextjs build step - disabling esmExternals as suggested here FirebaseExtended/reactfire#491 (comment) is now working for me so possibly a esm/cjs conflict. |
I was able to reproduce this issue. I will file it internally and follow up with the appropriate tracking info. |
I encountered the same bug. I see you're using Vue, are you also using Vitest as a test runner? To make my tests work in Vitest I had to force the usage of the commonjs version of Firestore, because @firebase/rules-unit-testing uses firebase/compat under the hood (see #6077 (comment)) export default defineConfig({
// ...
resolve: {
alias: process.env.VITEST ?
[{ find: /^@firebase\/firestore$/, replacement: `${__dirname}/node_modules/@firebase/firestore/dist/index.node.cjs.js` }]
: []
},
// ....
}) |
I am trying to update my unit tests to work with firebase v9. For firebase v8 I had used mocks and dependency injection, but this is harder with v9 as now every method (e.g. collection, getDoc, setDoc) is separated. In comes this guide: https://firebase.google.com/docs/rules/unit-tests I have it partially working with this new rules unit testing library, but it seems to break with a firebase v9 call to firestore
collection()
with this error:Steps to reproduce:
Relevant Code:
The reason I'm not simply switching to the v8 way of doing things is because that's the way my code works everywhere since I've migrated to v9. Perhaps I have the wrong approach all-together? Maybe I need some kind of mocking library to handle calls to firestore? Worth noting that I'm using the v9 compatibility library (because of firebase-ui).
The text was updated successfully, but these errors were encountered: