Skip to content
Preptima
mediumConceptDesignMidSeniorStaff

How do you test a Node service, and what do you refuse to mock?

6 min readUpdated 2026-08-15

Answer

Short answer

Drive business logic through injected dependencies rather than module mocks, intercept at the process boundary for outbound HTTP and time, and use a real database in a container for anything where the database is the logic — SQL, constraints, transactions and migrations.

Was this answer helpful?

Likely follow-ups

  • Your suite is green but a release broke on a unique-constraint violation. Where was the gap, and what test would have caught it?
  • How do you keep a Postgres-backed suite fast enough to run on every commit?
  • When is a contract test the right answer instead of either a mock or a live dependency?
  • How would you test code that depends on the current time and on a 30-second timeout?

Related questions

Further reading