TypeError -带Angular 的Jest配置

uurity8g  于 2023-02-10  发布在  Jest
关注(0)|答案(1)|浏览(156)

我正在为Angular 9应用程序使用jest
1.我安装了jest & jest预设Angular
1.在根目录下创建setupJest.ts文件并导入jest-preset-angular
1.在package.json中添加Jest配置

"jest": {
    "preset": "jest-preset-angular",
    "setupFilesAfterEnv": [
      "<rootDir>/setupJest.ts"
    ]
  }

1.修改测试脚本以使用Jest代替ng测试。
1.运行npm测试
我遇到类型错误

TypeError: Jest: a transform must export something.
at Promise.all._config.transform.map (~\node_modules\@jest\transform\build\ScriptTransformer.js:386:19)
at process._tickCallback (internal/process/next_tick.js:68:7)
9jyewag0

9jyewag01#

我的Jest文件看起来像这样,它运行

{
"preset": "jest-preset-angular",
"setupFilesAfterEnv": [
    "<rootDir>/setup-jest.ts"
],
"transformIgnorePatterns": [
    "node_modules/(?!@ngrx|ngx-socket-io)" 
],
"transform": {
    "^.+\\.(ts|js|html)$": "ts-jest"
},
"testPathIgnorePatterns": [
    "<rootDir>/node_modules/",
    "<rootDir>/dist/",
    "<rootDir>/src/test.ts"
],
"modulePaths": ["<rootDir>"]

}

相关问题