01 · Before and afterThe pattern
// before: added to every file, overrides the file's in-memory DB fake
vi.mock("@app/db", () => ({ default: {}, db: {} }));
// after: only in files without a fake, and if a fake exists, point the mock at it
vi.mock("@app/db", async () => { const { fakeDb } = await import("./__mocks__/db"); return { default: fakeDb, db: fakeDb }; });
vi.mock("@app/credentials", () => ({ getUserCredentials: vi.fn().mockResolvedValue([]) })); // same shape as real02 · Run it on your appThe check
For each module you mock in tests, does the mock return the same shape the real function does?
If the honest answer is no or not sure, this is worth a look before it reaches production.