0
我是JavaScript新手,我試圖在部署它之前測試我的Firebase雲端函數,但我得到的測試失敗了,弄清楚。當我運行我的摩卡測試時,我越來越...錯誤'myFunctions.keepTimesUpdated不是函數'在我的雲功能
TypeError: myFunctions.keepTimesUpdated is not a function
at Context.it (testing.js:45:32)
我真的不知道爲什麼。
這裏是我的testing.js
const chai = require('chai');
const assert = chai.assert;
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
const sinon = require('sinon');
describe('Cloud Functions',() => {
var myFunctions, configStub, adminInitStub, functions, admin;
before(() => {
admin = require('firebase-admin');
adminInitStub = sinon.stub(admin, 'initializeApp');
functions = require('firebase-functions');
configStub = sinon.stub(functions, 'config').returns({
firebase: {
databaseURL: 'https://hallpass-v2.firebaseio.com',
storageBucket: 'not-a-project.appspot.com',
}
});
myFunctions = require('/Users/mitchellgant/Documents/OldDesktop/XCode/HallPass-v2/functions/index')
});
after(() => {
configStub.restore();
adminInitStub.restore();
});
describe('keepTimesUpdated',() => {
it('should update the nextWeek val',() => {
const fakeEvent = {
data: new functions.database.DeltaSnapshot(null, null, null, null,'timeInfo/currentDate')
};
return myFunctions.keepTimesUpdated(fakeEvent);
})
});
})
,這裏是我的index.js
var functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
// // Start writing Firebase Functions
// // https://firebase.google.com/functions/write-firebase-functions
//
// exports.helloWorld = functions.https.onRequest((request, response) => {
// response.send("Hello from Firebase!");
// })
let keepTimesUpdated = functions.database.ref('timeInfo/currentDate').onWrite(async event => {
let snap = event.data;
let curDate = snap.value;
let nextWeekRef = snap.ref.parent.child('nextWeek');
let nextWeek = nextWeekRef.value;
let nextMonthRef = snap.ref.parent.child('nextMonth')
let nextMonth = nextMonthRef.value
let date = new Date();
let curMonth = date.getMonth() + 1;
// if (curDate >= nextWeek) {
// nextWeekRef.set(nextWeek + 604800000);
// snap.ref.parent.parent.child('Schools/{school}/teachers/{teacher}').child('needToUpdateWeekVals').set(true);
// }
// if (curMonth >= nextMonth) {
// nextMonthRef.set(nextMonth + 1);
// snap.ref.parent.parent.child('Schools/{school}/teachers/{teacher}').child('needToUpdateMonthVals').set(true);
// }
})
任何有識之士將是非常有益的。