Using babel-polyfill with Karma, Webpack and ES6
Thu, Mar 17, 2016
1 minute read

Enabling babel-polyfill when running unit tests using Karma, PhantomJS, Webpack and ES6

Unit tests started failing when lodash’s assign was replaced with Object.assign().

'undefined' is not a function (evaluating 'Object.assign(...)

Tests are bundled with Webpack first and then executed using Karma as test runner and PhantomJS.

Adding the following in karma.config.js solved the problem:

files: [
  'node_modules/babel-polyfill/dist/polyfill.js',
  ...
]

Hint on how to fix this issue was in karma-babel-preprocessor plugin documentation. Polyfill seems to work fine even though plugin itself is not used in the project.


Back to posts