测试无法运行测试用例退出 TypeError: Jest: a transform must export a `process` function
Posted
技术标签:
【中文标题】测试无法运行测试用例退出 TypeError: Jest: a transform must export a `process` function【英文标题】:Test unable to run test cases exits with TypeError: Jest: a transform must export a `process` function 【发布时间】:2021-08-26 17:09:33 【问题描述】://tsconfig.base.json “compileOnSave”:假, “编译器选项”: "baseUrl": "./", "outDir": "./dist/out-tsc", “源地图”:是的, “声明”:错误, “下级迭代”:真, “experimentalDecorators”:是的, “模块”:“esnext”, "moduleResolution": "节点", “importHelpers”:是的, “目标”:“es2015”, "typeRoots": ["node_modules/@types"], “lib”:[“es2018”,“dom”] , “角编译器选项”: “fullTemplateTypeCheck”:真, “严格注入参数”:真
//ts.spec.json
"extends": "./tsconfig.base.json",
"compilerOptions":
"outDir": "./out-tsc/spec",
"types": ["jest", "node"],
"esModuleInterop": true,
"emitDecoratorMetadata": true
,
"files": ["src/test.ts", "src/polyfills.ts"],
"include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
//setupTest.js
import 'jest-extended';
import 'jest-preset-angular/setup-jest';
import './globalMocks';
//jest dependancies list
"@types/jest": "~26.0.15",
"@types/node": "^12.11.1",
"@types/uuid": "^7.0.0",
"babel-jest": "^27.0.2",
"codelyzer": "^6.0.0",
"jest": "^26.6.3",
"jest-environment-jsdom-sixteen": "1.0.3",
"jest-extended": "^0.11.5",
"jest-junit": "^12.0.0",
"jest-preset-angular": "^9.0.0-next.3",
"ng-bullet": "~1.0.3",
"regenerator-runtime": "^0.13.7",
"rxjs-tslint-rules": "^4.34.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~4.0.5"
FAIL src/app/authentication/register/register.component.spec.ts
● Test suite failed to run
TypeError: Jest: a transform must export a `process` function.
at ScriptTransformer._getTransformer (node_modules/@jest/transform/build/ScriptTransformer.js:360:13)
at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:427:28)
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:569:40)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:607:25)
【问题讨论】:
【参考方案1】:使用 ts-node 和 ts-jest,它们都是 26.x 版本
"jest": "^26.6.3",
"ts-jest": "^26.5.5",
【讨论】:
以上是关于测试无法运行测试用例退出 TypeError: Jest: a transform must export a `process` function的主要内容,如果未能解决你的问题,请参考以下文章
反应笑话单元测试用例TypeError:无法读取未定义的属性'then'