Closed ankeshdave closed 5 years ago
This seems odd.
Although these steps should not be required, as the tests would fail on another level, please check:
@types/jest
package in your workspacetsconfig.spec.ts
contains "jest"
in the types
-arrayOtherwise this does not seem like an issue with this preset.
If possible, try to provide a minimal reproduction, so we can help you further.
Cheers and happy testing!
I am using
jest-preset-angular
to using jest for unit testing. (Earlier i was using karma). I have converted my tests usingjest-codemods
.I am getting jest test error when i run the test
TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option): src/app/mymodele/my-component.component.spec.ts:38:9 - error TS2554: Expected 3 arguments, but got 2. 38 jest.spyOn(component, 'mymethod').mockImplementation(); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
IDE is recognizing the
jest.spyOn
method but then the test runs this is displayedJest Debug file
{ "configs": [ { "automock": false, "browser": false, "cache": true, "cacheDirectory": "<user-profile>\\AppData\\Local\\Temp\\jest", "clearMocks": false, "coveragePathIgnorePatterns": [ "\\\\node_modules\\\\" ], "cwd": "<my-proj-root-dir>", "dependencyExtractor": null, "detectLeaks": false, "detectOpenHandles": false, "errorOnDeprecated": false, "filter": null, "forceCoverageMatch": [], "globalSetup": null, "globalTeardown": null, "globals": { "ts-jest": { "tsConfig": "<rootDir>/src/tsconfig.spec.json", "stringifyContentPathRegex": "\\.html$", "astTransformers": [ "<my-proj-root-dir>\\node_modules\\jest-preset-angular\\InlineHtmlStripStylesTransformer.js" ] } }, "haste": { "computeSha1": false, "providesModuleNodeModules": [], "throwOnModuleCollision": false }, "moduleDirectories": [ "node_modules" ], "moduleFileExtensions": [ "ts", "html", "js", "json" ], "moduleNameMapper": [ [ "@app/(.*)", "<my-proj-root-dir>\\src\\app\\$1" ], [ "@assets/(.*)", "<my-proj-root-dir>\\src\\assets\\$1" ], [ "@core/(.*)", "<my-proj-root-dir>\\src\\app\\core\\$1" ], [ "@env", "<my-proj-root-dir>\\src\\environments\\environment" ], [ "@src/(.*)", "<my-proj-root-dir>\\src\\src\\$1" ], [ "@state/(.*)", "<my-proj-root-dir>\\src\\app\\state\\$1" ], [ "helpers/(.*)", "<my-proj-root-dir>\\src\\helpers\\$1" ], [ "app/(.*)", "<my-proj-root-dir>\\src\\app\\$1" ], [ "environments/(.*)", "<my-proj-root-dir>\\src\\environments\\$1" ], [ "^src/(.*)$", "<my-proj-root-dir>\\src\\$1" ], [ "^app/(.*)$", "<my-proj-root-dir>\\src\\app\\$1" ], [ "^assets/(.*)$", "<my-proj-root-dir>\\src\\assets\\$1" ], [ "^environments/(.*)$", "<my-proj-root-dir>\\src\\environments\\$1" ] ], "modulePathIgnorePatterns": [], "name": "b6bd5a0b25dd9d0d8be554d366e12f3d", "prettierPath": "prettier", "resetMocks": false, "resetModules": false, "resolver": null, "restoreMocks": false, "rootDir": "<my-proj-root-dir>", "roots": [ "<my-proj-root-dir>\\src" ], "runner": "jest-runner", "setupFiles": [], "setupFilesAfterEnv": [ "<my-proj-root-dir>\\src\\setup-jest.ts" ], "skipFilter": false, "snapshotSerializers": [ "<my-proj-root-dir>\\node_modules\\jest-preset-angular\\AngularSnapshotSerializer.js", "<my-proj-root-dir>\\node_modules\\jest-preset-angular\\HTMLCommentSerializer.js" ], "testEnvironment": "<my-proj-root-dir>\\node_modules\\jest-environment-jsdom-thirteen\\build\\index.js", "testEnvironmentOptions": {}, "testLocationInResults": false, "testMatch": [ "**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[tj]s?(x)" ], "testPathIgnorePatterns": [ "\\\\node_modules\\\\" ], "testRegex": [], "testRunner": "<my-proj-root-dir>\\node_modules\\jest-jasmine2\\build\\index.js", "testURL": "http://localhost", "timers": "real", "transform": [ [ "^.+\\.(ts|js|html)$", "<my-proj-root-dir>\\node_modules\\ts-jest\\dist\\index.js" ] ], "transformIgnorePatterns": [ "<my-proj-root-dir>\\\\node_modules\\\\(?!@ngrx|jest-test)" ], "watchPathIgnorePatterns": [] } ], "globalConfig": { "bail": 0, "changedFilesWithAncestor": false, "collectCoverage": false, "collectCoverageFrom": null, "coverageDirectory": "<my-proj-root-dir>\\coverage", "coverageReporters": [ "json", "text", "lcov", "clover" ], "coverageThreshold": null, "detectLeaks": false, "detectOpenHandles": false, "errorOnDeprecated": false, "expand": false, "filter": null, "globalSetup": null, "globalTeardown": null, "json": false, "listTests": false, "maxConcurrency": 5, "maxWorkers": 4, "noStackTrace": false, "nonFlagArgs": [], "notify": false, "notifyMode": "failure-change", "passWithNoTests": false, "projects": null, "rootDir": "<my-proj-root-dir>", "runTestsByPath": false, "skipFilter": false, "testFailureExitCode": 1, "testNamePattern": "", "testPathPattern": "", "testResultsProcessor": null, "updateSnapshot": "new", "useStderr": false, "verbose": null, "watch": true, "watchman": true }, "version": "24.5.0" }
Check the typescript version you are using. I found the same issue where @types/jest uses functionality from typescript 2.8 and I was only on 2.4.2. In my case rolling @types/jest back to 23.3.12 fixed issue.
closed as not related to this preset
For me, the issue was fixed by replacing "@types/jest"
with "@jest/types"
in package.json
. Not related to presets tho, but Jest in general.
thanks for that @smith558
I am using
jest-preset-angular
to using jest for unit testing. (Earlier i was using karma). I have converted my tests usingjest-codemods
.I am getting jest test error when i run the test
IDE is recognizing the
jest.spyOn
method but then the test runs this is displayedJest Debug file