如何使用Firestore测试云功能?

时间:2018-01-15 03:08:50

标签: firebase google-cloud-functions google-cloud-firestore

我正在尝试测试云功能功能。 但是,在测试中(npm run test)我得到了这个错误。

为什么我收到此错误?如何解决?

TypeError: Path must be a string. Received undefined
at assertPath (path.js:7:11)
at Object.join (path.js:1218:7)
at database (node_modules/firebase-functions/lib/providers/firestore.js:36:45)
at Object.document (node_modules/firebase-functions/lib/providers/firestore.js:44:12)
at Object.<anonymous> (src/index.ts:6:21)
at Object.loadTypeScript (node_modules/espower-typescript/index.js:23:17)
at require (internal/module.js:20:19)
at Context.before (test/initialize-pair.ts:19:23)

这是我的index.ts 它作为一个真正的云功能函数。

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp(functions.config().firebase);
export const aFunc = functions.firestore.document('/users/{uid}').onUpdate(() => { console.log('called')});

谢谢

1 个答案:

答案 0 :(得分:0)

看起来您正在运行npm run test,而不了解您的特定测试脚本应该实际执行的操作。 Firebase CLI不提供用于自动测试功能的npm脚本。

如果您想对功能进行单元测试,read the advice in the documentation here

如果您想使用本地模拟器手动模拟您的功能事件,read the documentation here

相关问题