ENONET error while running jest-preset-angular

1.5k Views Asked by At

I am trying to integrate jest for my angular project for unit testing.

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.

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)screenshot of the path used in 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))" ] }

1

There are 1 best solutions below

0
On

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:

"@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. Once i changed the jest version to latest in that repo, it too stared giving the same weird path packages\core\src\.... error.

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. I tried with jest.spyOn().mockImplementation() too but with no success.

I suspect with the spyOn methods to cause the errors.