How do you test private methods?
Usually test private behavior through the public API that depends on it.
The question library
Explore practical questions, clear explanations, and code examples across developer technologies.
Showing 3565–3576 of 3610 questions
Usually test private behavior through the public API that depends on it.
Inject a clock or use fake timers to control time-dependent behavior.
Jest coverage can report statements, branches, functions, and lines.
Pure functions are ideal unit-test targets because identical inputs should produce identical outputs without side effects.
Mock external boundaries such as network, clock, filesystem, and persistence when needed, but keep domain logic real.
Integration testing checks that components work together across a boundary, such as a service and database, API and middleware, or application and message broker.
Unit tests isolate a small unit and usually replace collaborators; integration tests exercise real interactions between components.
Supertest sends HTTP requests to a Node.
NestJS Test.
Use a dedicated disposable database or isolated schema with the same engine and relevant version as production.
Testcontainers provisions disposable dependencies such as databases, brokers, and caches in containers for tests.
Use isolated fixtures, factories, transactions, unique test identifiers, or per-test schemas depending on concurrency and database behavior.