Closed lloydrichards closed 3 years ago
Solved my own problem 😅
Looks like I needed to import functions inside the beforeAll()
describe("Apiary Tests", () => {
let MyFunctions;
let wrappedOnUpdate: WrappedScheduledFunction | WrappedFunction;
beforeAll(() => {
MyFunctions = require("../index");
wrappedOnUpdate = testEnv.wrap(MyFunctions.apiaryUpdated);
return admin.firestore().doc(path).set(mock_apiaryDoc);
});
afterAll(() => {
testEnv.cleanup();
});
...
Just incase someone else has the same problem
Love this type of issue! 😄 Glad you were able to figure it out, closing this as part of a repo cleanup.
Version info
firebase-functions-test: 9.6.0
firebase-functions: 3.13.2
firebase-admin: 9.2.0
Test case
I have a unit test at the moment that is checking if a firebase function is correctly adding a file to my apps bucket. In the function I'm mostly using @google-cloud/storage but need to get the bucket name. At the head of the function, I call
const bucket = gcs.bucket(admin.storage().bucket().name);
in order to create anew Bucket()
. This works fine when deployed but when running unit tests using firebase-functions-test I get errors saying the bucket is unspecified.Steps to reproduce
Expected behavior
In jest I'm expecting the test to run and see whether the expected value is true or false
Actual behavior
Get this error saying the storageBucket isn't set, even though it clearly is.