I am using Jest with Vue-Test-Utils. The code I have been using looks like this:
beforeEach(() => {
wrapper = shallow(GridContainer, {
data: {
pageSize: count
},
propsData: {
userId,
managerId
}
})
})
In this example, I want to set the pageSize value before the life cycle mounted is called. The problem with the above code is that I have started getting the following warning when the tests run:
[Vue warn]: Do not use built-in or reserved HTML elements as component id: data
When I delete the data property above, the warning goes away.
Am I setting the data correctly? If so, what should I do about the warning?
Should I set the data another way?
Vue Test Utils is the official unit testing utility library for Vue. js. This is the documentation for Vue Test Utils v1, which targets Vue 2 and earlier.
The `mounted()` Hook in Vue The mounted() hook is the most commonly used lifecycle hook in Vue. Vue calls the mounted() hook when your component is added to the DOM. It is most often used to send an HTTP request to fetch data that the component will then render.
The Node. js provides a Vue. js data() method to the user. Basically in vue. js data() we defined collection of logic and stored in component using vue.
Please try like this:
beforeEach(() => {
wrapper = shallow(GridContainer, {
propsData: {
userId,
managerId
}
})
wrapper.setData({pageSize: count})
})
reference: setData https://vue-test-utils.vuejs.org/en/api/wrapper/setData.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With