Jest测试运行无法识别`jest.spyOn`

时间:2019-03-15 11:37:07

标签: angular reactjs typescript jestjs

我正在使用jest-preset-angular将玩笑用于单元测试。 (之前我在使用业力)。我已经使用jest-codemods转换了测试。

运行测试时我得到了开玩笑的测试错误

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识别出jest.spyOn方法,但随后测试运行此方法显示

Jest调试文件

{
  "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"
}

0 个答案:

没有答案