describe('makeUpperCase', () => {
// Test Case: setting messages/11111/original to 'input' should cause 'INPUT' to be written to
// messages/11111/uppercase
it('should upper case input and write it to /uppercase', () => {
// [START assertOnline]
// Create a DataSnapshot with the value 'input' and the reference path 'messages/11111/original'.
const snap = test.database.makeDataSnapshot('input', 'messages/11111/original');
// Wrap the makeUppercase function
const wrapped = test.wrap(myFunctions.makeUppercase);
// Call the wrapped function with the snapshot you constructed.
return wrapped(snap).then(() => {
// Read the value of the data at messages/11111/uppercase. Because `admin.initializeApp()` is
// called in functions/index.js, there's already a Firebase app initialized. Otherwise, add
// `admin.initializeApp()` before this line.
return admin.database().ref('messages/11111/uppercase').once('value').then((createdSnap) => {
// Assert that the value is the uppercased version of our input.
assert.equal(createdSnap.val(), 'INPUT');
});
});
// [END assertOnline]
})
});
Actual behavior
IMO the following part is misleasing:
// Because `admin.initializeApp()` is
// called in functions/index.js, there's already a Firebase app initialized. Otherwise, add
// `admin.initializeApp()` before this line.
Calling admin.initializeApp() without arguments doesn't make much sense when running unit tests locally. When this method is called without arguments it reads the config from FIREBASE_CONFIG. Normally, when runing test on localhost such a variable doesn't exist.
Expected behavior
The documenation should, at least, mention that the funcion must either be called with credentials object passed as an argument, or the FIREBASE_CONFIG env variable must be set before running unit tests.
Steps to reproduce
Here's the snipper from the documenatation:
Actual behavior
IMO the following part is misleasing:
Calling
admin.initializeApp()
without arguments doesn't make much sense when running unit tests locally. When this method is called without arguments it reads the config fromFIREBASE_CONFIG
. Normally, when runing test on localhost such a variable doesn't exist.Expected behavior
The documenation should, at least, mention that the funcion must either be called with credentials object passed as an argument, or the
FIREBASE_CONFIG
env variable must be set before running unit tests.