【发布时间】:2022-01-23 06:33:12
【问题描述】:
我正在尝试为我的 firebase 云功能设置单元测试。但收到此错误
错误:Wrap 函数仅适用于
onCallHTTP 函数,不适用于onRequest。
这就是我的 app.test.ts 的样子
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-unused-vars */
import {stub} from "sinon";
import * as admin from "firebase-admin";
import funcTest from "firebase-functions-test";
admin.initializeApp();
describe("Index Test", function() {
let adminInitStub:any;
let appCloudFunction:any;
const test = funcTest();
before(async () => {
adminInitStub = stub(admin, "initializeApp");
appCloudFunction = await import("../index");
});
after(() => {
adminInitStub.restore();
test.cleanup();
});
it("should always pass", function() {
const wrapped = test.wrap(appCloudFunction.app);
wrapped(null);
});
});
我的云函数(index.ts)看起来像这样
import * as functions from "firebase-functions";
import app from "./app/app";
exports.app = functions.https.onRequest(app);
这里的应用程序是一个简单的快速应用程序。
谁能帮我解决这个问题?
【问题讨论】:
-
我认为错误信息很清楚。不支持您尝试执行的操作。如果您有添加对 onRequest 支持的功能请求,则应直接向 Firebase 提出问题。 Stack Overflow 帮不了你。
标签: firebase unit-testing google-cloud-functions