0

我有一个有趣的项目,我想在其中执行这个测试文件(在项目/_ _ 测试 _ _/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)

任何人都知道我如何能够开玩笑来执行这个测试?谢谢 !

4

0 回答 0