我正在尝试设置 Firebase Cloud Functions 存储库来运行摩卡测试。import * as firebase from "firebase-functions-test";但是,当我使用or时,它会引发以下错误const firebase = require("firebase-functions-test")();。您可以在我的代码中看到我什至还没有调用实际的 firebase 函数,所以我认为这是一个设置问题。
问题:要使用导入语法运行 mocha 测试以进行 Firebase 函数测试,我需要进行哪些更改?
工作测试代码
import { assert } from "chai";
describe("Sanity Check", () => {
it("should pass", () => {
assert.equal(0, 0);
});
});
Run Code Online (Sandbox Code Playgroud)
使用require测试代码失败
const test = require("firebase-functions-test")();
import { assert } from "chai";
describe("Sanity Check", () => {
it("should pass", () => {
assert.equal(0, 0);
test.cleanup();
});
});
Run Code Online (Sandbox Code Playgroud)
使用导入失败的代码
import * as firebase from …Run Code Online (Sandbox Code Playgroud) javascript mocha.js firebase typescript google-cloud-functions