PhantomJS does not work with Karma in Angular2 project

倾然丶 夕夏残阳落幕 提交于 2019-12-01 16:21:14
B.LASLEDJ

In fact, you don't have to wait for phantomjs 2.5 release.

  • npm install --save-dev karma-phantomjs-launcher

  • in karma.conf.js

    • add require('karma-phantomjs-launcher') to the plugins section
    • add PhantomJS to the browsers
  • npm install --save intl

  • in src/polyfill.ts
    • add import 'intl'; (uncomment at the bottom)
    • add import "core-js/client/shim"; to the Evergreen requirements section
  • In src/tsconfig.spec.json set the target to es5.

Ref: https://stackoverflow.com/a/42539894/7683428

Miroslav Jonas

Since Chrome supports now (as of version 59) headless running, there's no reason any more to use outdated PhantomJS. Unless you cannot update/install chrome on target machine. If you have included karma-chrome-launcher in karma.conf you can now just specify:

browsers: ['ChromeHeadless']

There's also possibility to use the Canary edition via ChromeCanary or ChromeCanaryHeadless.

My current work around is to target es5 for the tests only.

tsconfig.spec.json

{
    "compilerOptions": {
        ...
        "target": "es5",
        ...
}

.angular-cli.json

{
    "project": {
        "name": "client"
    },
    "apps": [
        {
            ...
            "tsconfig": "tsconfig.app.json",
            "testTsconfig": "tsconfig.spec.json",
            ...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!