-
Notifications
You must be signed in to change notification settings - Fork 56
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
Gen2 / TypeScript: Snapshot from 'makeDocumentSnapshot' Doesn't Work for 'onDocumentCreated' #205
Comments
The same issue happens with const beforeSnap = fnTest.firestore.makeDocumentSnapshot(
{ foo: 'bar' },
'Profile/1',
);
const afterSnap = fnTest.firestore.makeDocumentSnapshot(
{},
'Profile/1',
);
const change = fnTest.makeChange(beforeSnap, afterSnap);
await wrapped(change); And in the v2
I also catched that The
|
@JessRascal seems like v2 wrapped function expects a cloud event, not a change/snapshot object. So if you wrap your input into a cloud event object type, it works. See: https://github.com/firebase/firebase-functions-test/blob/master/src/cloudevent/mocks/firestore/helpers.ts#L68 await wrapped({ data: change }); |
Would be nice if they updated the docs to reflect this https://firebase.google.com/docs/functions/unit-testing#constructing_test_data |
Version info
firebase-functions-test: 3.1.0
firebase-functions: 4.4.1
firebase-admin: 11.9.0
Test case
Firebase Cloud Function
Unit Test
Note: Using Vitest but I believe it would be the same result with Jest, etc.
Steps to reproduce
Run the unit test against the Firebase function and it will result in a Cannot read properties of undefined (reading 'original') when trying to create the 'original' variable in the function (
const original = event.data?.data().original;
).This is because
event.data.data()
is undefined.Expected behavior
The document snapshot created in the unit test with
makeDocumentSnapshot
is in the correct format to be passed intoonDocumentCreated
so that its data can be read.Actual behavior
The 'original' variable cannot be created in the Firebase function because it can't read the
data
object in the passed inevent
resulting in the following error...I guess this is due to
makeDocumentSnapshot
creating aDocumentSnapshot
and theevent
inonDocumentCreated
expected to have a type ofFirestoreEvent<QueryDocumentSnapshot | undefined, { documentId: string; }>
.I can't find any alternative to
makeDocumentSnapshot
that should be used in this scenario for gen2 functions though so I'm guessing this isn't supported yet?If I create an object that contains the document snapshot as the value of a
data
parameter, it will workI'm not sure how much of this library is currently expected to work with the gen2 Firebase functions, but I couldn't find this issue already logged and the gen2 samples don't cover
onDocumentCreated
functions.Cheers
Jess
The text was updated successfully, but these errors were encountered: