Giter Club home page Giter Club logo

Comments (9)

JamieLottering avatar JamieLottering commented on September 26, 2024 5

I was under the impression that using shallow over mount essentially ignores all of the unregistered child components. From what I'm seeing though it causes a runtime error because they aren't registered with Vue.

So not necessarily wanting it to intelligently traverse my component and look for tags that aren't registered. I just thought this was the default behavior. Otherwise I wasn't sure what the purpose was calling shallow over just calling mount with the stubs property.

Maybe some confusion on my side or on the documentation side.

from vue-test-utils.

Teresast avatar Teresast commented on September 26, 2024 4

I meet same issue, all my function is work without any warning, but occur "[Vue warn]: Unknown custom element:" when I run unit test, but all my unit test is passed, just have a lot of this warn.

All my components is register like this:

const sharedComponents = {
install(Vue) {
Vue.component('v-input', Input);
Vue.component('popup', Popup);
},
};

Vue.use(sharedComponents);

new Vue({
el: '#app',
...
});

I'm confused why it's not work in unit test?

from vue-test-utils.

MaruaEl avatar MaruaEl commented on September 26, 2024 4

I solved by adding the global components as stubs -> read here
#894

from vue-test-utils.

Austio avatar Austio commented on September 26, 2024 3

You are correct in that it will only stub registered vue components, but it does on both your component instance and globally on the root vue.

Could you check that your component is registered in global vue and that you are not passing a localVue property to the shallow? To check you could do something like this in your spec before the assert. If it logs an empty object then you know that b-button is not registered globally and that is why it is not being stubbed globally.

console.log (Vue.options.components)

from vue-test-utils.

Austio avatar Austio commented on September 26, 2024

Thanks for reporting and for jfiddle. Could you expand on what you are expecting? I think you are saying that you would like vue-test-utils to be able to stub out any custom html element that isn't registered in vue as a component.

from vue-test-utils.

JamieLottering avatar JamieLottering commented on September 26, 2024

In fact even the documentation for shallow describes the behavior this way

Returns Wrapper of first DOM node or Vue component matching selector.
Stubs all child components.

from vue-test-utils.

JamieLottering avatar JamieLottering commented on September 26, 2024

Ok, I think I understand now.

The problem is my child components were globally registered and not locally. That's most likely why it has a problem stubbing them.

from vue-test-utils.

JamieLottering avatar JamieLottering commented on September 26, 2024

That's what I was missing. Totally forgot to include the file that registers my global components.

Thank you for your help!

from vue-test-utils.

OmgImAlexis avatar OmgImAlexis commented on September 26, 2024

@Teresast those are all installed globally, it seems to have them stubbed in shallowMount you need to install them like so.

import Popup from './popup.vue';

new Vue({
    el: '#app',
    components: {
        Popup
    },
    ...
});

from vue-test-utils.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.