Skip to content

Commit

Permalink
Fix firestore mocking for test
Browse files Browse the repository at this point in the history
  • Loading branch information
mlev committed Dec 16, 2023
1 parent 34d72f9 commit 8c4407b
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions packages/gcp-firestore/src/firestore/connect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -21,7 +27,7 @@ describe("connect", () => {
connectFirestore();

expect(Firestore).toHaveBeenLastCalledWith({ projectId: undefined });
})
}),
);

it("connects to app projectId if not running on gcp", async () => {
Expand Down Expand Up @@ -83,7 +89,7 @@ describe("connect", () => {
connectFirestoreAdmin();

expect(firestoreV1.FirestoreAdminClient).toHaveBeenLastCalledWith({ projectId: undefined });
})
}),
);

it("connects to app projectId if not running on gcp", async () => {
Expand Down

0 comments on commit 8c4407b

Please sign in to comment.