[@exp] rules unit testing #4715
-
Hi, so far using firebase@exp has been great (35% bundle size reduction 🎉) but it broke all my unit tests 😕 If I use the following import * as firebase from '@firebase/rules-unit-testing'
const app = firebase.initializeTestApp({…})
export const db = app.firestore() in (for instance) const batch = writeBatch(db) I get
Should I open an issue in firebase-tools or is there a workaround? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 24 replies
-
@akauppi except a couple of firebase events triggered cloud functions my app is totally client-side based. So, client-side, I have CRUD functions for my entities that use firestore primitives. These CRUD functions have the database dependency injected as a parameter for easier testing. But now I cannot inject firestore test databases anymore as their implementation is totally different from the firebase@exp firestore implementation I use on the client side. Is it a clearer description? |
Beta Was this translation helpful? Give feedback.
-
We have some planned changes for @yuchenshi Anything you want to add? |
Beta Was this translation helpful? Give feedback.
-
Aug 2021 update: We've released See our quickstarts on using the new RUTv2 API (docs: guide | reference). The instructions below are still possible for power users who wants to keep dependencies to a minimum (but you're pretty much on your own if you choose this path). Earlier response: As promised, |
Beta Was this translation helpful? Give feedback.
-
@yuchenshi Nice that Rules v2 is getting attention. You may want to consider two minor things about the tests you linked to, before releasing:
Why do these matter? For one, any sample you ship is educational to the larger audience, some of whom are novices and will simply copy-paste what's out there. Second, tests should be even clearer and more readable than code, since they can be used also by managers and such to discuss about features - and see what's being tested. Great that Firebase has good testing tools. |
Beta Was this translation helpful? Give feedback.
Aug 2021 update: We've released
@firebase/rules-unit-testing
v2, which is a major revamp and works with v9 JS SDK (modular / compat).See our quickstarts on using the new RUTv2 API (docs: guide | reference). The instructions below are still possible for power users who wants to keep dependencies to a minimum (but you're pretty much on your own if you choose this path).
Earlier response:
As promised,
useFirestoreEmulator(db, host, port, {mockUserToken: {...}})
is now released. Try it out with the new Beta modular SDK and let us know what you think!useDatabaseEmulator
also got a similar upgrade and storage iscoming soonalso released.