在开玩笑中使用“ automock:true”时,如何解决:“未找到core-js es6-reflect”?

时间:2019-05-28 09:16:15

标签: angular typescript unit-testing jestjs

我试图在我的Angular测试中使用开玩笑选项'automock:true',但是当我将此选项设置为true时,我得到了错误:

●测试套件无法运行

core-js es6-reflect not found!

> 1 | import 'jest-preset-angular';
    | ^
  2 | 
  3 | import './jestGlobalMocks'; // browser mocks globally available for every test
  4 | 

  at Object.<anonymous> (node_modules/jest-preset-angular/setupJest.js:9:11)
  at Object.<anonymous> (node_modules/jest-preset-angular/index.js:1:45)
  at Object.<anonymous> (src/setupJest.ts:1:1)
      at Array.forEach (<anonymous>)

当我将选项设置为“ false”时,不会出现任何错误。我似乎无法弄清楚该如何解决。

来自我的package.json:

"lint-staged": {
    "*.scss": [
      "stylelint --syntax=scss"
    ],
    "*.{ts,scss,html}": [
      "pretty-quick --staged",
      "git add"
    ],
    "*.ts": [
      "tslint"
    ],
    "ignore": [
      "documentation/*"
    ]
  },
  "jest": {
    "preset": "jest-preset-angular",
    "setupFilesAfterEnv": [
      "<rootDir>/src/setupJest.ts"
    ],
    "moduleNameMapper": {
      "bla/env(.*)$": "<rootDir>/src/environments/environment/$1",
      "bla/icons(.*)$": "<rootDir>/src/vendor/icons.ts",
      "bla/messages(.*)$": "<rootDir>/src/messages/$1"
    }
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^7.0.0",
    "@angular/cdk": "^7.0.1",
    "@angular/common": "~7.0.0",
    "@angular/compiler": "~7.0.0",
    "@angular/core": "~7.0.0",
    "@angular/forms": "~7.0.0",
    "@angular/http": "~7.0.0",
    "@angular/material": "^7.0.1",
    "@angular/material-moment-adapter": "^7.0.1",
    "@angular/platform-browser": "~7.0.0",
    "@angular/platform-browser-dynamic": "~7.0.0",
    "@angular/router": "~7.0.0",
    "@fortawesome/angular-fontawesome": "0.1.1",
    "@fortawesome/fontawesome-svg-core": "1.2.2",
    "@fortawesome/free-solid-svg-icons": "5.2.0",
    "@hackages/ngxerrors": "^7.0.0",
    "@netbasal/spectator": "^3.9.1",
    "@ng-select/ng-select": "^2.12.0",
    "bootstrap": "^4.1.3",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.5.4",
    "hammerjs": "^2.0.8",
    "jquery": "^3.3.1",
    "moment": "^2.22.2",
    "ngx-currency": "^1.5.1",
    "ngx-dropzone-wrapper": "^7.1.0",
    "ngx-toastr": "^9.1.1",
    "popper.js": "^1.14.4",
    "rxjs": "~6.3.3",
    "stylelint-scss": "^3.3.2",
    "stylelint-selector-bem-pattern": "^2.0.0",
    "web-animations-js": "^2.3.1",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-builders/jest": "^7.4.2",
    "@angular-devkit/build-angular": "~0.10.0",
    "@angular/cli": "~7.0.2",
    "@angular/compiler-cli": "~7.0.0",
    "@angular/language-service": "~7.0.0",
    "@compodoc/compodoc": "^1.1.8",
    "@netbasal/spectator": "~3.2.1",
    "@types/jest": "^24.0.13",
    "@types/node": "~8.9.4",
    "codelyzer": "^4.5.0",
    "gulp": "3.9.1",
    "gulp-footer": "1.1.2",
    "gulp-header": "1.8.12",
    "gulp-replace": "0.6.1",
    "husky": "^1.1.2",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "jest": "^24.8.0",
    "jest-extended": "^0.11.1",
    "lint-staged": "^7.3.0",
    "ng-mocks": "^7.8.0",
    "prettier": "^1.14.3",
    "pretty-quick": "^1.8.0",
    "protractor": "~5.4.0",
    "shallow-render": "^8.0.5",
    "stylelint": "^9.6.0",
    "stylelint-color-format": "^0.2.0",
    "stylelint-config-recommended": "^2.1.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.1.1"
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged",
      "pre-push": "npm run build"
    }
  }

我的jest.config.js:

module.exports = {
  testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
  transform: {
    '^.+\\.(ts|js|html)$': 'ts-jest'
  },
  moduleFileExtensions: ['ts', 'js', 'html'],
  collectCoverage: true,
  coverageReporters: ['text-summary'],
  verbose: true,
  automock: true,
  snapshotSerializers: [
    'jest-preset-angular/AngularSnapshotSerializer.js',
    'jest-preset-angular/HTMLCommentSerializer.js'
  ]
};

还有我的setupJest.ts:

import 'jest-preset-angular';

import './jestGlobalMocks';

0 个答案:

没有答案