Comments (9)
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.
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.
I solved by adding the global components as stubs
-> read here
#894
from vue-test-utils.
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.
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.
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.
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.
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.
@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)
- `RouterLink.useLink` is missing when using `RouterLinkStub`. HOT 3
- Test child component, which is the root element HOT 3
- Computed value does not update when data updates
- isVisible() not seeing display: none using vitest with jsdom HOT 4
- Testing component with onBeforeRouteLeave hook raising "No active route record was found" warning HOT 1
- vue2 引入 element2. 页面存在table 表格 jest 测试报错 HOT 1
- *.svg?inline issues
- Errors in `setup()` are silent if `render()` throws an error HOT 6
- Check style changes on hover HOT 1
- setData on writable computed property does not seem to work as it does in VTU.1
- classes documentation
- Support Vue 2.7.16 HOT 2
- Vue test utils not updating template when testing composables
- TypeError: $setup.mergeProps is not a function
- Data property is already defined in Props. HOT 1
- Unable to use vitest spy within vue/nuxt 3 component methods. HOT 3
- `findComponent` doesn't find anything when using `@vue/compat` HOT 1
- Components with TS generic HOT 1
- event.keyCode is deprecated
- Change mocks mid-test
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-test-utils.