From 8c4407bf64011d6a7e0e3e17f44e02a2356cd258 Mon Sep 17 00:00:00 2001 From: Martin Levett Date: Sat, 16 Dec 2023 15:29:07 +1100 Subject: [PATCH] Fix firestore mocking for test --- .../src/firestore/connect.test.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/gcp-firestore/src/firestore/connect.test.ts b/packages/gcp-firestore/src/firestore/connect.test.ts index a0f56a4..a7a3a13 100644 --- a/packages/gcp-firestore/src/firestore/connect.test.ts +++ b/packages/gcp-firestore/src/firestore/connect.test.ts @@ -4,12 +4,18 @@ import { withEnvVars } from "@mondokit/gcp-core/dist/__test/test-utils.js"; import { connectFirestore, connectFirestoreAdmin } from "./connect.js"; import { initEmulatorConfig, initTestConfig } from "../__test/test-utils.js"; -vi.mock("@google-cloud/firestore", () => ({ - Firestore: vi.fn(), - v1: { - FirestoreAdminClient: vi.fn(), - }, -})); +vi.mock("@google-cloud/firestore", () => { + const mockedFirestore = { + Firestore: vi.fn(), + v1: { + FirestoreAdminClient: vi.fn(), + }, + }; + return { + default: mockedFirestore, + ...mockedFirestore, + }; +}); describe("connect", () => { describe("connectFirestore", () => { @@ -21,7 +27,7 @@ describe("connect", () => { connectFirestore(); expect(Firestore).toHaveBeenLastCalledWith({ projectId: undefined }); - }) + }), ); it("connects to app projectId if not running on gcp", async () => { @@ -83,7 +89,7 @@ describe("connect", () => { connectFirestoreAdmin(); expect(firestoreV1.FirestoreAdminClient).toHaveBeenLastCalledWith({ projectId: undefined }); - }) + }), ); it("connects to app projectId if not running on gcp", async () => {