question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Breaks karma testing with phantomjs

See original GitHub issue

Below is the error received when running karma with phantomjs:

04 02 2017 23:00:40.353:INFO [karma]: Karma v1.4.1 server started at http://0.0.0.0:9876/
04 02 2017 23:00:40.355:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
04 02 2017 23:00:40.359:INFO [launcher]: Starting browser PhantomJS
04 02 2017 23:00:40.997:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket -cO0ACHZ7ins7g78AAAA with id 58034973
PhantomJS 2.1.1 (Mac OS X 0.0.0) LOG: 'Attempting to configure 'style' with descriptor '{"enumerable":true,"configurable":true}' on object '[object HTMLHtmlElement]' and got error, giving up: TypeError: Attempting to configurable attribute of unconfigurable property.'
PhantomJS 2.1.1 (Mac OS X 0.0.0) LOG: 'Attempting to configure 'style' with descriptor '{"enumerable":true,"configurable":true}' on object '[object HTMLHtmlElement]' and got error, giving up: TypeError: Attempting to configurable attribute of unconfigurable property.'
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  TypeError: undefined is not a constructor (evaluating 'b.style._set(a.propertyName(c),d)')
  at webpack:///~/web-animations-js/web-animations.min.js:15:0 <- src/polyfills.ts:3498
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  TypeError: undefined is not a constructor (evaluating 'b.style._set(a.propertyName(c),d)')
  at webpack:///~/web-animations-js/web-animations.min.js:15:0 <- src/polyfills.ts:3498

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:8
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
mscudlikcommented, Apr 3, 2017

I pretty much had the same issue as described her when i updated angular cli to 1.0.0 and angular to 4.0.1 today.

This is the solution i came up with, which seems to work so i wanted to briefly how i managed to solve it.

I created a new project with angular cli and saw that the polyfill.ts template has changed:

/**
 * This file includes polyfills needed by Angular and is loaded before the app.
 * You can add your own extra polyfills to this file.
 *
 * This file is divided into 2 sections:
 *   1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
 *   2. Application imports. Files imported after ZoneJS that should be loaded before your main
 *      file.
 *
 * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
 * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
 * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
 *
 * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
 */

/***************************************************************************************************
 * BROWSER POLYFILLS
 */

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
// import 'core-js/es6/symbol';
// import 'core-js/es6/object';
// import 'core-js/es6/function';
// import 'core-js/es6/parse-int';
// import 'core-js/es6/parse-float';
// import 'core-js/es6/number';
// import 'core-js/es6/math';
// import 'core-js/es6/string';
// import 'core-js/es6/date';
// import 'core-js/es6/array';
// import 'core-js/es6/regexp';
// import 'core-js/es6/map';
// import 'core-js/es6/set';

/** IE10 and IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js';  // Run `npm install --save classlist.js`.

/** IE10 and IE11 requires the following to support `@angular/animation`. */
// import 'web-animations-js';  // Run `npm install --save web-animations-js`.


/** Evergreen browsers require these. **/
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';


/** ALL Firefox browsers require the following to support `@angular/animation`. **/
// import 'web-animations-js';  // Run `npm install --save web-animations-js`.



/***************************************************************************************************
 * Zone JS is required by Angular itself.
 */
import 'zone.js/dist/zone';  // Included with Angular CLI.



/***************************************************************************************************
 * APPLICATION IMPORTS
 */

/**
 * Date, currency, decimal and percent pipes.
 * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
 */
// import 'intl';  // Run `npm install --save intl`.

as you can see there is a new entry for web-animations which i uncommented (as well as most of the other polyfills):

/**
 * This file includes polyfills needed by Angular and is loaded before the app.
 * You can add your own extra polyfills to this file.
 *
 * This file is divided into 2 sections:
 *   1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
 *   2. Application imports. Files imported after ZoneJS that should be loaded before your main
 *      file.
 *
 * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
 * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
 * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
 *
 * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
 */

/***************************************************************************************************
 * BROWSER POLYFILLS
 */

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/set';

/** IE10 and IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js';  // Run `npm install --save classlist.js`.

/** IE10 and IE11 requires the following to support `@angular/animation`. */
import 'web-animations-js';  // Run `npm install --save web-animations-js`.


/** Evergreen browsers require these. **/
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';


/** ALL Firefox browsers require the following to support `@angular/animation`. **/
// import 'web-animations-js';  // Run `npm install --save web-animations-js`.



/***************************************************************************************************
 * Zone JS is required by Angular itself.
 */
import 'zone.js/dist/zone';  // Included with Angular CLI.



/***************************************************************************************************
 * APPLICATION IMPORTS
 */

/**
 * Date, currency, decimal and percent pipes.
 * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
 */
import 'intl';  // Run `npm install --save intl`.

Afterwards i removed the web-animations from my script section in .angular-cli.json

Then all my tests ran already, besides the one where the component actually uses animations. To solve this, i import the NoopAnimationsModule and it works 😃

import { TestBed, async } from '@angular/core/testing';

import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { animationPlayerFactory } from './animation-player.factory';

import { AppComponent } from './app.component';

describe('AppComponent', () => {
  beforeEach(async(() => {
    TestBed.configureTestingModule({
      import: [
        NoopAnimationsModule
      ],
      declarations: [
        AppComponent
      ],
    }).compileComponents();
  }));

  // tests...

});

This pretty much solved the problem. Now for me it would be interesting if this also works for you and if you think thus is a “proper” solution.

Thanks and best regards, Matthias

2reactions
Kozlocommented, Sep 8, 2017

I had a similar problem. Initially I tried to import BrowserAnimationsModule per the suggestion (in the app I also had to import this for the animations to work), but in PhantomJS the test still didn’t work until I replaced BrowserAnimationsModule with NoopAnimationsModule.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Karma jasmine test fails when running on PhantomJS
What was breaking my code was a duplicate key in my angular template. Wow. Ahh the joys of being a web developer.
Read more >
Faster Karma test runs that work in VSTS with Chrome ...
Most examples I've seen use PhantomJS as a headless browser, and it works ok. But on my current project, we have 4,700+ JavaScript...
Read more >
Javascript Testing with Jasmine and Karma - Eldarion
As for the Karma test runner, I needed the karma-jquery adapter so ... Lastly, since we will be running these tests in PhantomJS...
Read more >
Using PhantomJS With Karma - DZone
This guide will walk through the process of generating a new Angular application, configuring PhantomJS in the Karma test runner, ...
Read more >
Headless OPA5 testing with Karma and PhantomJS - SAP Blogs
To match this, OPA5 tests can be run with Karma and PhantomJS. While Karma will serve the files to the browser without the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found