Vuetify: [Bug Report] Cannot unit test Vuetify component - TypeError: undefined is not a constructor

Created on 19 Feb 2018  路  5Comments  路  Source: vuetifyjs/vuetify

Versions and Environment

Vuetify: 1.0.1
Vue: 2.5.13
Browsers: Chrome 63.0.3239.132
OS: Windows 10

Steps to reproduce

I made a simple Vuetify component based on vue-webpack-boilerplate and I wanted to unit test it using PhantomJS, Karma, Mocha and Chai. Therefore I made a simple test suite:

import Vue from 'vue'
import Vuetify from 'vuetify'
import Component from '@/Component'
Vue.use(Vuetify)
describe('Component', () => {
  it('should mount', async () => {
    var Constructor = Vue.extend(Component)
    var vm = new Constructor().$mount()
  })
})

Expected Behavior

The test should run.

Actual Behavior

Instead I get the following type error:

  TypeError: undefined is not a constructor (evaluating 'Array.from({ length: length }, function (v, k) {
      return k;
    })')
  at webpack:///node_modules/vuetify/dist/vuetify.js:303:0 <- index.js:14997

And the function at vuetify.js:303 is:

function createRange(length) {
  return [].concat(_toConsumableArray(Array.from({ length: length }, function (v, k) {
    return k;
  })));
}

Reproduction Link

Other comments

What is the cause of the type error?

wontfix

Most helpful comment

I recently encountered this issue with v1.0.0-beta.13.
I will share the solution here in case somebody will encounter it too.

Import babel-polyfill in test/unit/index.js.

import 'babel-polyfill';

import Vue from 'vue'
import Vuetify from 'vuetify'

Vue.use(Vuetify)
...

Links: Babel Polyfill usage

All 5 comments

Thanks. The workaround is to import 'babel-polyfill'.

Actually, after importing and declaring the babel-polyfill as detailed in the documentation (quick start) it is still not working with IE11, with the same error as the one reported above (line 303 of vuetify.js). Any idea what could be the problem. TIA

By changing
entry: './src/main.js',
, to
entry: ['babel-polyfill', './src/main.js'],
in webpack.config.js it worked.
(BTW sorry to pollute an already closed issue...)

I recently encountered this issue with v1.0.0-beta.13.
I will share the solution here in case somebody will encounter it too.

Import babel-polyfill in test/unit/index.js.

import 'babel-polyfill';

import Vue from 'vue'
import Vuetify from 'vuetify'

Vue.use(Vuetify)
...

Links: Babel Polyfill usage

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Antway picture Antway  路  3Comments

dschreij picture dschreij  路  3Comments

aaronjpitts picture aaronjpitts  路  3Comments

Webifi picture Webifi  路  3Comments

jofftiquez picture jofftiquez  路  3Comments