NestJS ts-jest config / decorator metadata error in CI
ts-jest compiles test files with its own tsconfig lookup. If that config lacks the decorator options Nest needs, tests fail to compile or DI metadata is missing even though nest build works.
What this error means
jest fails during transform with a decorator "error TS1240/TS1241", or tests run but DI resolves undefined because ts-jest did not emit decorator metadata.
● Test suite failed to run
src/cats/cats.service.spec.ts:5:3 - error TS1240: Unable to resolve signature of
property decorator when called as an expression.Common causes
ts-jest points at a tsconfig without decorator options
ts-jest uses the nearest tsconfig or a configured one; if that file lacks experimentalDecorators/emitDecoratorMetadata, decorated test code fails.
A separate test tsconfig drifted from the build config
The build tsconfig has the options but the test tsconfig does not, so behavior differs between nest build and jest.
How to fix it
Point ts-jest at a config with decorator options
- Set the tsconfig ts-jest uses in the transform options.
- Ensure that tsconfig enables both decorator options.
- Re-run jest so decorated classes compile with metadata.
transform: {
'^.+\\.ts$': ['ts-jest', { tsconfig: 'tsconfig.json' }],
}Share a base tsconfig
Have both build and test tsconfig extend one base that sets the decorator options so they cannot diverge.
{ "extends": "./tsconfig.base.json" }How to prevent it
- Extend a single base tsconfig for build and test.
- Set the tsconfig ts-jest uses explicitly in jest config.
- Run the full jest suite in CI to catch transform-level errors.