Vuetify: 1.0.1
Vue: 2.5.13
Browsers: Chrome 63.0.3239.132
OS: Windows 10
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()
})
})
The test should run.
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;
})));
}
What is the cause of the type error?
This is because pjs does not support ES6 features.
Further reading:
https://github.com/ariya/phantomjs/issues/14216
https://github.com/babel/babel/issues/5682
https://github.com/necolas/react-native-web/issues/409#issuecomment-295057475
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
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-polyfillintest/unit/index.js.Links: Babel Polyfill usage