score:20

Accepted answer

Ok after I added this @babel/preset-typescript into my presets, that error went away:

"test": {
  "presets": [
    "@babel/preset-typescript",  // <---
    [
      "next/babel",
      {
        "preset-env": {
          "modules": "commonjs"
        }
      }
    ]
  ],
  "plugins": [
    [
      "styled-components",
      {
        "ssr": true,
        "displayName": true
      }
    ]
  ]
}

score:-2

your const declarion does not have a variable name. const variableName: Type = new Type() or const variableName: Type; or const variableName = new Type;

score:0

In case just having the @babel/typescript preset does not work. You could try the following:

  1. Rename the failing test file to either .ts or .tsx depending on whether you have JSX in your test (in this case Astronaut.test.tsx)
  2. Update your jest config docs (in this case package.json), add
"moduleFileExtensions": [
    "js",
    "ts",
    "tsx"
],

Related Query

More Query from same tag