Invental/Review lessons/Tests that can never fail

Tests that can never fail

Mocks must return the real shapes

A blanket “mock it everywhere” fix can quietly replace the test doubles that make tests meaningful. Then the suite turns green, or red, for the wrong reason. A mock has to match the real module's exports and return shapes, not just exist.

01 · Before and afterThe pattern

TypeScript
// 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 real

02 · 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.

Want this checked on your code?

Tell us what you are building and what worries you. We match a senior reviewer to your code and confirm scope before anything starts.

— Get in touch
hi@invental.co ↗
— Or
— What to include

A link or short description of the code or system, what you want checked, your stack, and when you need the answer. No repository access is needed until scope is agreed.

— Or leave a note
We reply within one business day.