You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constadmin=require("firebase-admin");admin.initializeApp();const{project_id: projectId}=require("../../serviceAccount.json");// Setup tests to be in "online" mode (see https://firebase.google.com/docs/functions/unit-testing#initializing)consttest=require("firebase-functions-test")({databaseURL: `http://localhost:8080`,storageBucket: `${projectId}.appspot.com`,
projectId,},__dirname+"/../../serviceAccount.json");constmyFunc=require("../myfunc");it("writes to itself",async()=>{// Make snapshot for state of database beforehandconstbeforeSnap=test.firestore.makeDocumentSnapshot({},"users/foo");// Make snapshot for state of database after the changeconstafterSnap=test.firestore.makeDocumentSnapshot({name: "foo"},"users/foo");constchange=test.makeChange(beforeSnap,afterSnap);// Call wrapped function with the Change objectconstwrapped=test.wrap(myFunc);awaitwrapped(change);// Assert that the user document was updatedexpect(afterSnap.get("name_upper")).toEqual("FOO");});
Steps to reproduce
Start emulator
Run test, prefixed with FIRESTORE_EMULATOR_HOST=localhost:8080
Expected behavior
afterSnap should have a new field, name_upper with value FOO
Actual behavior
It only has the original field , name:
expect(received).toEqual(expected) // deep equality
Expected: "FOO"
Received: undefined
I am, however, able to write to a new document in the emulator Firestore instance from within the cloud function, e.g:
constref=admin.firestore().doc('/users/bar');awaitref.set({name: 'bar'});// Document is now visible in emulator Firestore instance
The text was updated successfully, but these errors were encountered:
itsravenous
changed the title
change.after.ref.update() changes not persisted when running against emulator suite
Writes to document that triggered function not persisted when running against emulator suite
Dec 9, 2020
itsravenous
changed the title
Writes to document that triggered function not persisted when running against emulator suite
Writes to document that triggered function are not persisted when running against emulator suite
Dec 9, 2020
@itsravenous Did you ever manage to figure this out? Running into the same problem.
Nope, I ended up writing integration tests instead, using firebase-admin to write data to firestore and then reading it back within a wait function to make assertions on it to verify the cloud function did its job. Not ideal, but I had to get some sort of coverage and move on!
Version info
firebase-functions-test: 0.2.3
firebase-functions: 3.13.0
firebase-admin: 9.4.1
Test case
myfunc.js: (based on this example about writing to the same document that triggered the function)
myfunc.test.js:
Steps to reproduce
FIRESTORE_EMULATOR_HOST=localhost:8080
Expected behavior
afterSnap
should have a new field,name_upper
with valueFOO
Actual behavior
It only has the original field ,
name
:expect(received).toEqual(expected) // deep equality Expected: "FOO" Received: undefined
I am, however, able to write to a new document in the emulator Firestore instance from within the cloud function, e.g:
The text was updated successfully, but these errors were encountered: