Jest test on typescript file syntax error: "interface is a reserved word in strict mode"
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 } ] ]}
In case just having the @babel/typescript
preset does not work.You could try the following:
- Rename the failing test file to either
.ts
or.tsx
depending on whether you have JSX in your test (in this caseAstronaut.test.tsx
) - Update your jest config docs (in this case package.json), add
"moduleFileExtensions": [ "js", "ts", "tsx"],
your const declarion does not have a variable name.const variableName: Type = new Type()orconst variableName: Type;orconst variableName = new Type;