[Vuejs]-Error in running unit test for Vue webapp

0👍

The vueTest function in utils is trying to load the Vue instance into the body tag:

const vm = new Class({
  replace: false,
  el: 'body'
})
return vm

The unit tests do not load index.html as an entry point into the app, but rather the individual components that you want to test; Therefore, you do not have access to document or html elements and the component is never mounted. I’d suggest using vm.$mount():

If elementOrSelector argument is not provided, the template will be rendered as an off-document element.

You could change the above lines to something like the following

const vm = new Class();
vm.$mount();
return vm;

Your tests should now have access to the $el property.

Leave a comment