kulshekhar / ts-jest

A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.

Home Page:https://kulshekhar.github.io/ts-jest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: "Decorator arguments must be moved inside parentheses:.."

markkelsall opened this issue · comments

commented

Version

29.1.2

Steps to reproduce

Building an Express app using razzlejs that uses babel & the required babel plugins to support decorators in TS5 (not experimental)

Application builds, runs great, just can't use jest to test with following output:

I have the following dependencies:
ts-jest: 29.1.2
babel-jest: 29.7.0
typescript: 5.3.2

jest config for ts-jest:
transform = {
"ts-jest",
{
tsConfig: "tsconfig.json",
babelConfig: "babel.config.js",
},
}

babel config:

presets: [['@babel/preset-env', {targets: {node: 'current'}}], "@babel/preset-react", "@babel/preset-typescript"],
    plugins: [
        ["@babel/plugin-proposal-decorators", { version: "2023-05" }],
        [
            "@babel/plugin-proposal-class-properties",
            {
                loose: true,
            },
        ],
        [
            "@babel/plugin-transform-runtime",
            {
                regenerator: true,
            },
        ],
        ["@babel/plugin-proposal-private-methods", { loose: true }],
        ["@babel/plugin-proposal-private-property-in-object", { loose: true }],
        "@babel/plugin-proposal-object-rest-spread",
        "@babel/plugin-proposal-optional-chaining",
        "@babel/plugin-proposal-nullish-coalescing-operator",
        "@babel/plugin-transform-async-to-generator",
        "@babel/plugin-syntax-class-properties",
        "@babel/plugin-syntax-object-rest-spread",
        "@babel/plugin-transform-react-inline-elements",
        "@babel/plugin-transform-react-constant-elements",
        "@babel/plugin-syntax-dynamic-import",
    ],

Get the following output:
SyntaxError: /path/to/controllers/Controller.ts: Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'. (7:49)

If I remove the ts-jest config that points to babelConfig then it falls over saying to add the babel decorators plugin, so I know it's picking up my working babel config. However it seems to using an old/different way of compiling the decorators in the build. Does it support that stage of the decorators proposal? 202305?

Thanks

Expected behavior

Expect compiled output to be aligned with the specified version of decorators so that jest can read the file correctly

Actual behavior

SyntaxError: /path/to/controllers/Controller.ts: Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'. (7:49)

Debug log

Will attach after created

Additional context

No response

Environment

System:
    OS: macOS 14.1.2
    CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.17 - ~/.yarn/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
  npmPackages:
    jest: ^29.7.0 => 29.7.0
commented

Also found this stackoverflow but not found a resolution - https://stackoverflow.com/questions/76136892/unexpected-token-for-typescript-decorator

commented

Update: Switching the transform pattern match of .ts files to use babel-jest works, but not with ts-jest