When trying to execute a test written in typescript 2.7.1 with Jest, it encounters a syntax error for the following code snippet:
module X.Y.Z {
}
The error message displayed is:
SyntaxError: C:\Users\jest-typescript\__tests__\example.spec.ts: Unexpected token, expected ";" (1:7)
> 1 | module X.Y.Z {
| ^
2 |
3 | }
4 |
at Parser.raise (node_modules/@babel/parser/lib/index.js:6325:17)
The tests are being run using the command line interface as shown below:
jest -t --config=jest.config.js
It seems like the babel parser is struggling with the syntax provided. Unfortunately, the typescript syntax cannot be changed due to it being a legacy codebase. There doesn't appear to be an option within the jest.config.js
file to specify a version of typescript.
The content of my jest.config.js
file is as follows:
module.exports = {
coverageDirectory: "coverage",
testEnvironment: "node",
testMatch: [
"**/__tests__/**/*.[jt]s?(x)"
]
};
Any suggestions on how to resolve these syntax errors without refactoring the existing code?