2017-03-23 28 views
0

私はJavaScriptを初めて使用していますが、導入前にFirebase Cloud機能をテストしようとしていますが、把握するため。私はモカのテストを実行するときに私は得ています...エラー '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); 
    // } 
}) 

です。

答えて

0

あなたの関数をエクスポートする必要があります:変更let keepTimesUpdated = ...からexports.keepTimesUpdated = ...

関連する問題