我有一个开玩笑的项目,我想在其中执行此测试文件(在project / _ _测试_ _ / example.spec.ts中):
module X.Y.Z {
let r = X.Y.Z.C;
describe("A", ()=>{
it("Does A stuff", ()=>{
expect(r).toEqual("someContent");
});
})
}
源代码(位于project / src / source.ts中):
module X.Y.Z {
export const C = "someContent";
}
我的笑话配置:
module.exports = {
globals: {
'ts-jest': {
"tsConfig": "<rootDir>/tsconfig.test.json"
}
},
// transform: {
// "\\.(ts|js)x?$": "ts-jest",
// },
coverageDirectory: "coverage",
testEnvironment: "jsdom",
testMatch: [
'<rootDir>/**/__tests__/**/*.ts'
]
};
tsConfig.test.json文件:
{
"compileOnSave": false,
"compilerOptions": {
"allowJs": true,
"moduleResolution": "classic",
"inlineSources": true,
"declaration": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types",
"./node_modules/typescript/lib/lib.d.ts"
]
},
"files": [
"./src/source.ts"
]
}
由于语法错误,测试的执行失败:
FAIL __tests__/example.spec.ts
● Test suite failed to run
SyntaxError: C:\Users\Workspace\jest-typescript\__tests__\example.spec.ts: Unexpected token, expected ";" (1:7)
> 1 | module X.Y.Z {
| ^
2 |
3 | let r = X.Y.Z.C;
4 |
at Parser.raise (node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:6325:17)
任何人都知道我如何能够开玩笑地执行此测试?谢谢!