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.

"[Vue warn]: Unknown custom element:" when running unit tests

See original GitHub issue

I’ve imported Vuetify in my main.js file:

import Vue from 'vue';
import VueResource from 'vue-resource';
import Vuetify from 'vuetify';
import App from './App';
import router from './router';

Vue.use(Vuetify);
Vue.use(VueResource);

When I run any Karma unit tests that test components that include Vuetify elements in their templates I get the following errors:

image

The test itself actually passes, I would just like to clean this up.

Any ideas? Is there another way to register Vuetify components for testing purposes? Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

41reactions
edoecohencommented, Mar 22, 2017

Solved! Correct, Vuetify was not getting registered. So I added:

import Vuetify from 'vuetify';
Vue.use(Vuetify);

in the test file itself but that still caused issues. So I dug into the Vuetify index.js file and saw this:

if (typeof window !== 'undefined' && window.Vue) {
  window.Vue.use(plugin)
}

And because my karma config was setup to use PhantomJS as the browser there was no ‘window’. So I changed it to use ‘Chrome’ and it now works fine.

Another alternative I found was to add:

Vue.config.ignoredElements = [
    'v-icon', 'v-card', 'v-card-text'
];

to the test file and include any failing components.

Hope this helps others!

4reactions
albizurescommented, Oct 8, 2017

for me, I had to add this in my setup file

const hooks = require('require-extension-hooks')
const Vue = require('vue')
const Vuetify = require('vuetify').default

require('browser-env')()
Vue.config.productionTip = false
+Vue.use(Vuetify)

hooks('vue').plugin('vue').push()
hooks(['vue', 'js']).plugin('babel').push()

+window.Vue = Vue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vuetify Jest Unknown custom element <v-*> - Stack Overflow
It looks like a autogenerated bug when generating Vuetify project from the CLI . In short, it's because Vuetify is not registered in...
Read more >
5 mins to fix jest tests for app with: Unknown custom element
If you are writing unit tests and want to test the functionality of a component individually, then setup the shallowMount function and test...
Read more >
Vue Test Utils: [Vue warn]: Unknown custom element: <v ...
I get this error message: [Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to ......
Read more >
Vue+jest+Vuetify 2.0.*+unit testing : Getting an error as "[Vue ...
This error occurs because vuetify is not registered to your test project. To do so you have to create an index.js file in...
Read more >
Quasar Unknown custom element error in unit test-Vue.js
Coding example for the question Quasar Unknown custom element error in unit test-Vue.js.
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