【发布时间】:2021-08-30 02:06:53
【问题描述】:
我的package.json 文件包含以下内容:
...
"jest": "jest --runInBand",
"test": "firebase emulators:exec 'npm run jest'"
...
这允许我使用正在运行的 Firebase 模拟器运行基于 jest 的测试。
考虑以下代码:
describe("MyTests", () => {
const req = supertest(app);
let user: admin.auth.UserRecord;
let idToken: string | undefined;
beforeAll(async () => {
const email = "test@gmail.com";
const password = "password";
user = await admin.auth().createUser({ email: email, password: password });
await auth.signInWithEmailAndPassword(email, password);
idToken = await auth.currentUser?.getIdToken();
});
// actual tests
我在哪里创建 Firebase 用户,该用户又会触发一个函数 (functions.auth.user().onCreate(foo))。
我确实注意到这个 foo 函数是在 开玩笑的测试套件运行之后执行的:
Test Suites: 1 passed, 1 total
Tests: 3 passed, 3 total
Snapshots: 0 total
Time: 14.841 s, estimated 16 s
Ran all test suites.
✔ Script exited successfully (code 0)
i functions: Beginning execution of "us-central1-foo"
i emulators: Shutting down emulators.
i functions: Stopping Functions Emulator
i functions: Waiting for all functions to finish...
i functions: Finished "us-central1-foo" in ~1s
如何等待它从 beforeAll() 函数内部执行?
【问题讨论】:
-
您是如何找到解决方案的?
-
@Piotr 不,仍在等待帮助
-
我的“解决方案”是等待 2.5 秒????
标签: firebase jestjs firebase-tools