最近我的应用程序升级到了Angular 11。Jest已被设置为默认测试框架。运行npm测试会导致以下错误:
● Test suite failed to run
TypeError: Jest: a transform must export a `process` function.
20 | @Component({
21 | selector: 'app-bx-input-textbox',
> 22 | template: require('./bx-input-textbox.component.html'),
| ^
23 | styles: [String(require('./bx-input-textbox.component.scss'))],
24 | providers: [
25 | {
at ScriptTransformer._getTransformer (node_modules/@jest/transform/build/ScriptTransformer.js:357:15)
at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:419:28)
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:523:40)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
at src/app/core/components/bx-input-textbox/bx-input-textbox.component.ts:22:15
at Object.<anonymous> (src/app/core/components/bx-input-textbox/bx-input-textbox.component.ts:38:1)
//jest.config.js
module.exports = {
testEnvironment: "jsdom",
transform: {
".+\\.(css|styl|less|sass|scss)$": "<rootDir>/node_modules/jest-css-modules-transform",
"\\.(ts|js)$": ['ts-jest']
},
setupFilesAfterEnv: ['./jest.setup.js'],
globals: {
"ts-jest": {
tsConfig: {
// allow js in typescript
allowJs: true,
},
},
},
// If you need to test a specifc file just include it here
//testMatch: ['**/repository.jobs.spec.ts'],
testMatch: []
};
包版本“@angular-builders/jest”:“12.1.0”,“@types/jest”:“24.9.1”,“ts-jest”:“26.0.0”,“jest”:“24.9.0”,
我尝试了不同的配置与jest.config.js文件,但无法解决此错误。任何解决此问题的建议都将有所帮助。
7条答案
按热度按时间vuktfyat1#
您的
ts-jest
版本必须与jest
版本匹配。1szpjjfi2#
已将jest和ts-jest升级到v27以修复此问题
e7arh2l63#
遇到了同样的问题与“ts-jest”:“^27.0.5”,并通过恢复为“ts-jest”进行修复:“^26.4.2”
rslzwgfq4#
您可能还需要升级
jest-cli
沿着jest
和ts-jest
。gorkyyrv5#
如果您的
ts-jest
版本是27.x.x
,则必须安装27....
的匹配jest
版本。只需安装从
jest 27
获取最新版本rqcrx0a66#
擦拭节点模块和.jest文件夹终于摆脱了这一点。
px9o7tmv7#
jest和ts-jest的版本不一定匹配。
真正需要的是版本兼容。
当我遇到这个问题时,我正在使用jest@^28.1.1,令人惊讶的是,ts-jest的版本不存在28.1.1。
我最终升级ts-jest为我找到的最接近的一个。对我来说,我最终得到了以下版本