Jest / ts-jest not using global tsconfig?

#1

Hi, I have a problem with Reflect-Metadata in Jest, and only in Jest. It works fine within the application itself.

In tsconfig.json, “experimentalDecorators” is set to true:

{
  "compileOnSave": false,
  "compilerOptions": {
    "target": "es5",
    "module": "esnext",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "sourceRoot": "src",
    "sourceMap": true,
    "allowJs": true,
    "baseUrl": "src",
    "skipLibCheck": true,
    "lib": [
      "es2017", "dom"
    ]
  },
  "exclude": [
  ],
  "include": [
    "./src/**/*.ts",
    "./test/**/*.ts",
    "./custom_typings/**/*.d.ts"
  ],
  "atom": {
    "rewriteTsconfig": false
  }
}

In Jest I want to retreive the actions from the Test Class.

// returns false
expect(Reflect.hasMetadata(GlobalActionsSymbal, GetActionsTestClass.constructor)).toBe(true);

@actions(["delete",
    "download",
    "preview",
    "read",
    "write",
    "upload"])
export class GetActionsTestClass {
    constructor() {

    }
}

I’ve tried to add the reflect-metadata import on top of the test file as descibed on github, but that made no difference.
I’ve tried to add the experimentalDecorators setting to the jest config as well, but also without success. Pointing to the main tsconfig from the package.json also did nothing:

"jest": {
   "globals": {
      "ts-jest": {
         "tsConfig": "<rootDir>/tsconfig.json"
      }
   ....
},

Clue anyone?

1 Like
#2

Can you create a minimal sample replicating the issue?

2 Likes
#3

Will try, have to deal with deadline first, albeit without jest tests for now

2 Likes