1

我有一个使用 angular cli 创建的项目。我使用 cli 生成新组件,当使用带有以下堆栈的 PhantomJS 时,即使是最基本的测试也会失败。

× should create an instance
   PhantomJS 2.1.1 (Windows 8 0.0.0)
   Failed: undefined is not a constructor (evaluating 'attr.name.startsWith(_I18N_ATTR_PREFIX)')
   http://localhost:9876/_karma_webpack_/vendor.bundle.js:48660:70
   filter@[native code]
   _visitAttributesOf@http://localhost:9876/_karma_webpack_/vendor.bundle.js:48660:24
   visitElement@http://localhost:9876/_karma_webpack_/vendor.bundle.js:48603:32
   visit@http://localhost:9876/_karma_webpack_/vendor.bundle.js:40053:62
   http://localhost:9876/_karma_webpack_/vendor.bundle.js:48595:59
   forEach@[native code]
   visitElement@http://localhost:9876/_karma_webpack_/vendor.bundle.js:48594:31
   visit@http://localhost:9876/_karma_webpack_/vendor.bundle.js:40053:62
   http://localhost:9876/_karma_webpack_/vendor.bundle.js:48595:59
   forEach@[native code]
   visitElement@http://localhost:9876/_karma_webpack_/vendor.bundle.js:48594:31
   visit@http://localhost:9876/_karma_webpack_/vendor.bundle.js:40053:62
   http://localhost:9876/_karma_webpack_/vendor.bundle.js:48595:59
   forEach@[native code]
   visitElement@http://localhost:9876/_karma_webpack_/vendor.bundle.js:48594:31

我怀疑我的 npm 包组合存在一些不兼容。这是我的 package.json

"dependencies": {
  "@angular/animations": "^5.0.2",
  "@angular/common": "^5.0.2",
  "@angular/compiler": "^5.0.2",
  "@angular/core": "^5.0.2",
  "@angular/forms": "^5.0.2",
  "@angular/http": "^5.0.2",
  "@angular/platform-browser": "^5.0.2",
  "@angular/platform-browser-dynamic": "^5.0.2",
  "@angular/router": "^5.0.2",
  "angularfire2": "^5.0.0-rc.4",
  "core-js": "^2.4.1",
  "crds-styles": "^1.3.1",
  "firebase": "^4.6.2",
  "intl": "^1.2.5",
  "ng2-toastr": "^4.1.2",
  "ngx-bootstrap": "1.9.3",
  "rxjs": "^5.5.2",
  "zone.js": "^0.8.14"
},
"devDependencies": {
  "@angular/cli": "1.5.4",
  "@angular/compiler-cli": "^5.0.2",
  "@angular/language-service": "^5.0.2",
  "@types/jasmine": "2.5.38",
  "@types/jasminewd2": "~2.0.2",
  "@types/node": "~6.0.89",
  "codelyzer": "^4.0.1",
  "firebase-tools": "^3.15.4",
  "jasmine-core": "~2.6.0",
  "jasmine-spec-reporter": "~4.2.0",
  "karma": "~1.7.0",
  "karma-chrome-launcher": "~2.1.1",
  "karma-cli": "~1.0.1",
  "karma-coverage-istanbul-reporter": "^1.2.1",
  "karma-jasmine": "~1.1.0",
  "karma-jasmine-html-reporter": "^0.2.2",
  "karma-mocha-reporter": "2.2.4",
  "karma-phantomjs-launcher": "^1.0.4",
  "karma-teamcity-reporter": "^1.0.0",
  "prettier": "^1.9.2",
  "protractor": "~5.1.2",
  "replace": "^0.3.0",
  "ts-node": "~2.0.0",
  "tslint": "~5.7.0",
  "tslint-config-prettier": "^1.6.0",
  "typescript": "2.5.3"
}

有任何想法吗?

4

1 回答 1

0

您使用startsWith()ECMAScript 6 中引入的方法。Phantom JS 目前不支持此 JS 版本。您可以在此处查看当前状态:https ://github.com/ariya/phantomjs/issues/14506 。您可以改用 ChromeHeadless 或跳过包含 ES6 代码的文件(但不会对其进行测试)。

于 2017-12-15T17:09:22.433 回答