In plain words
A test double replaces a real dependency during a test: a stub returns a canned answer, a mock records how it was called, and a fake is a small working version, like an in-memory database.
Where you see it
Harbor's upgrade flow asks Stripe to charge the team's card. In the test, a stand-in payments client answers with a successful charge or a declined one, so the test runs offline in milliseconds and nobody pays anything.
What goes wrong
- Mocking the thing you meant to test
If the test replaces the function that calculates the price, it only checks that the stand-in returns what you told it to. Replace what sits at the edges, such as Stripe, email and the clock, and run your own logic for real.
- A stand-in that no longer matches the real service
Your stub returns { status: "failed" }, while Stripe actually reports a decline as an error with a code such as card_declined. The tests stay green and production breaks. Copy stub responses from the provider's docs or a real test-mode call.
- Stand-ins that leak between tests
A module-level stub set to decline in one test is still declining in the next, so results depend on the order tests run in. Reset them between tests, for example with vi.resetAllMocks() in afterEach.
What to tell your agent
Quick check
Sign in to earn +10 XP for itA test for Harbor's upgrade flow mocks Stripe, the database and the calculatePrice function. It passes. What has it proved?