首页 > 解决方案 > 如何对预定的 Firebase 功能进行单元测试?

问题描述

我已经编写了一个预定函数,如下所述:https ://firebase.google.com/docs/functions/schedule-functions

我现在如何测试这个功能?当我包装这个函数时(就像我对任何其他云函数一样),有一个错误说:“类型'TestFunction'上不存在属性'wrap'。”

const functionWrapper = test.wrap(function);

有没有其他方法可以测试这些功能?

标签: firebasegoogle-cloud-functions

解决方案


我发现的一种解决方法是将我的代码隔离在一个函数中,并从预定函数中调用该函数。我测试的时候,不是调用调度函数,而是直接调用隔离函数。

前任:

export const dailyJob = functions.pubsub
        .schedule('0 0 * * *')
        .onRun(async context => {
    return isolatedFunction();
})

export function isolatedFunction() {
    ...
}

推荐阅读