Don't Mock What You Don't Own
There is a testing anti-pattern that's easy to fall into. Your code relies on a third-party library, so you mock it to keep tests fast and isolated. The tests go green. But mocking a library you didn't write means your test is verifying your understanding of that tool — not the tool itself. When the library ships a breaking change, your mocked tests keep passing. Your code crashes in production.
Only mock what you own:
// Don't mock the library directly
jest.mock('third-party-lib'); // Tests your assumptions, not reality
// Mock your adapter instead
jest.mock('./my-adapter'); // Tests behavior you control
If you need to interact with a third-party tool, wrap it first. Create your own adapter — PaymentProcessor instead of raw Stripe calls, EmailService instead of direct SendGrid integration. Now you own the interface, which means you control both sides of the mock. Your test implementation and your real implementation stay in sync because you wrote them both. A mocked interface you own is a meaningful test. A mocked interface you don't is just documented assumptions.
When the third-party library changes, you update the wrapper in one place and the rest of your tests remain valid. The wrapper isn't just a design pattern — it's what makes your test suite trustworthy at the boundary where your code meets the outside world.