NestJS ConfigService and external client provider override precedence in Test.createTestingModule
0 reputation · 13 Jul 2025, 21:53 UTC
Goal
Test a NestJS module that depends on an external HTTP client without loading production credentials into the test process. The client is provided through ConfigModule and ConfigService, and tests should replace only the client boundary with a test double using Test.createTestingModule.
Constraint
It is unclear whether overriding ConfigService values is sufficient, or whether the client provider token itself must be overridden. Because a client can read configuration in its constructor, a config-only override may capture the wrong value or be ignored entirely. Global ConfigModule registration may also change which module owns the override, and module initialization can fail on missing credentials before the double is installed. Behavior differs between @nestjs/testing minor versions that expose useMocker and those that rely on overrideProvider and useValue.
Decision needed
Should tests override the external client provider token directly, or is overriding ConfigService values reliably equivalent? How should the override target be chosen when ConfigModule is global versus non-global, and what version assumption applies to useMocker versus overrideProvider?