简体   繁体   English

运行jest-preset-angleular时ENONET错误

[英]ENONET error while running jest-preset-angular

I am trying to integrate jest for my angular project for unit testing. 我正在尝试将jest集成到我的角度项目中以进行单元测试。

I followed the instructions from this link . 我按照此链接中的说明进行操作。

I am facing a weird error as ENOENT: no such file or directory, open 'E:\\source-code\\packages\\core\\src\\view\\ng_module.ts' when i run. 我遇到一个奇怪的错误,如ENOENT: no such file or directory, open 'E:\\source-code\\packages\\core\\src\\view\\ng_module.ts'

My folder structure doesnt have a folder named package .After a lot of digging i found that packages\\core\\src\\view\\ng_module.ts' is used by a npm package(angular :P) 我的文件夹结构没有名为package的文件夹。经过大量挖掘后,我发现npm软件包使用packages\\core\\src\\view\\ng_module.ts' (角度:P) 在angular中使用的路径的屏幕截图

i dont know how this error is being thrown which doesnt happen when i run through karma 我不知道如何通过业力抛出此错误

This is my config for jest "jest": { "preset": "jest-preset-angular", "setupTestFrameworkScriptFile": "<rootDir>/src/setupJest.ts", "globals": { "ts-jest": { "tsConfigFile": "src/tsconfig.spec.json", "useBabelrc": true }, "__TRANSFORM_HTML__": true }, "transform": { "^.+\\\\.(ts|html)$": "<rootDir>/node_modules/jest-preset-angular/preprocessor.js", "^.+\\\\.js$": "babel-jest" }, "transformIgnorePatterns": [ "<rootDir>/node_modules/(?!(@ngrx|ngx-dialog|ng-infinity))" ] } 这是我对jest "jest": { "preset": "jest-preset-angular", "setupTestFrameworkScriptFile": "<rootDir>/src/setupJest.ts", "globals": { "ts-jest": { "tsConfigFile": "src/tsconfig.spec.json", "useBabelrc": true }, "__TRANSFORM_HTML__": true }, "transform": { "^.+\\\\.(ts|html)$": "<rootDir>/node_modules/jest-preset-angular/preprocessor.js", "^.+\\\\.js$": "babel-jest" }, "transformIgnorePatterns": [ "<rootDir>/node_modules/(?!(@ngrx|ngx-dialog|ng-infinity))" ] }配置"jest": { "preset": "jest-preset-angular", "setupTestFrameworkScriptFile": "<rootDir>/src/setupJest.ts", "globals": { "ts-jest": { "tsConfigFile": "src/tsconfig.spec.json", "useBabelrc": true }, "__TRANSFORM_HTML__": true }, "transform": { "^.+\\\\.(ts|html)$": "<rootDir>/node_modules/jest-preset-angular/preprocessor.js", "^.+\\\\.js$": "babel-jest" }, "transformIgnorePatterns": [ "<rootDir>/node_modules/(?!(@ngrx|ngx-dialog|ng-infinity))" ] }

Time to answer my own question. 是时候回答我自己的问题了。

It seems to be a version issue. 看来是版本问题。

At the time of writing this answer, the latest version is: 在撰写此答案时,最新版本为:

 "@types/jest": "^22.0.1",
 "jest": "^22.0.4",
 "jest-preset-angular": "^5.0.0"

The one which supports my project(in angular v4) is: 支持我的项目(在angular v4中)的是:

"@types/jest": "^20.0.7",
"jest": "^20.0.4",
"jest-preset-angular": "^2.0.5"

after this those errors stopped to occur. 之后,这些错误停止发生。

I checked this result againt this git repo too (also written in ng4) :P. 我也再次检查了这个结果到这个git repo (也写在ng4中):P。 Once i changed the jest version to latest in that repo, it too stared giving the same weird path packages\\core\\src\\.... error. 一旦我在该仓库中将开玩笑的版本更改为最新版本,它也开始盯着同样的奇怪路径packages\\core\\src\\....错误。

But some new errors started to happen now. 但是现在开始出现一些新的错误。 I am using jest.spyOn().mockReturnValue() which throws errors in actual component function, which shouldnt be case, since the function call should be mocked and use the provided return value. 我正在使用jest.spyOn().mockReturnValue()在实际的组件函数中引发错误,不应该这样,因为应该jest.spyOn().mockReturnValue()函数调用并使用提供的返回值。 I tried with jest.spyOn().mockImplementation() too but with no success. 我也尝试过jest.spyOn().mockImplementation()但没有成功。

I suspect with the spyOn methods to cause the errors. 我怀疑使用spyOn方法会导致错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 相当于 jest-preset-angular 中的 and.callThrough() - Equivalent of and.callThrough() in jest-preset-angular 使用 angular 工作区配置 `jest-preset-angular` - Configure `jest-preset-angular` with angular workspace Angular 8 和 jest - 找不到文件:jest-preset-angular/InlineHtmlStripStylesTransformer.js - Angular 8 and jest - File not found: jest-preset-angular/InlineHtmlStripStylesTransformer.js 如何在 jest.config.js 中设置 tsconfig 路径。 Angular 8. 开玩笑预设角度 - How to setup tsconfig paths in jest.config.js. Angular 8. jest-preset-angular Angular 4 + Jest-Preset-Angular:使用从文件导入的触发器在主机上测试动画 - Angular 4 + Jest-Preset-Angular : testing animation on host with trigger imported from file 模块<rootDir>未找到转换选项中的 /node_modules/jest-preset-angular/preprocessor.js - Module <rootDir>/node_modules/jest-preset-angular/preprocessor.js in the transform option was not found 在 Angular 中使用 Jest 运行测试用例时,“无法解决 CustomTranslationLoader 的所有参数”错误 - 'Can't resolve all parameters for CustomTranslationLoader ' error while running test cases using Jest in Angular 使用 IntelliJ 在 NX Workspace 中运行 Jest 测试时出现“错误:未找到预设 jest.preset.js” - "Error: Preset jest.preset.js not found" when using IntelliJ to run Jest tests in NX Workspace 在 @nrwl/nx 工作区中运行 Jest 测试时出错 - Error while running Jest tests in @nrwl/nx workspace 在角度2应用程序中运行时出现错误 - ng serve error while running in angular 2 application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM