Javascript 错误';myFunctions.KeepTimesUpdate不是一个函数';在我的云函数中
我是JavaScript新手,我正在尝试在部署Firebase云函数之前测试它,但我得到了一个失败的测试,我似乎真的无法弄清楚。当我进行摩卡咖啡测试时,我得到Javascript 错误';myFunctions.KeepTimesUpdate不是一个函数';在我的云函数中,javascript,firebase,google-cloud-functions,Javascript,Firebase,Google Cloud Functions,我是JavaScript新手,我正在尝试在部署Firebase云函数之前测试它,但我得到了一个失败的测试,我似乎真的无法弄清楚。当我进行摩卡咖啡测试时,我得到 TypeError: myFunctions.keepTimesUpdated is not a function at Context.it (testing.js:45:32) 我真的不知道为什么 这是我的testing.js const chai = require('chai'); const assert = chai.
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);
// }
})
任何洞察都会非常有用。您需要导出函数:更改
让KeepTimesUpdate=…
到导出。KeepTimesUpdate=…