[英]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)
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.