-
Notifications
You must be signed in to change notification settings - Fork 669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't set data for localVue #481
Comments
You can set wrapper.vm.$root = { loading: true }
wrapper.vm.$forceUpdate() Or you can pass in a parent component with the const Parent = {
data() {
return {
loading: "asdas"
};
}
};
const wrapper = shallowMount(TestComponent, {
parentComponent: Parent
}); |
@eddyerburgh it's not help const mountComp = (data) => {
const wrap = mount(ModeCard, {
propsData: data,
localVue,
});
wrap.setData({
$root: {
currentLang: 'ru',
},
});
return wrap
}; i anyway got |
If you're trying to set currenLang on your root instance, use: wrap.setData({
currentLang: 'ru',
}); |
@eddyerburgh yes, it's help. Thank you. |
@eddyerburgh after update to 1.0.0-beta.20, i can't again set data on $root. |
Oh, now it's work with |
I can't make it work neither with mocks or setData
$root.loading is undefined in both cases + with setData i got error not to change root data dynamicly |
You can set wrapper.vm.$root = { loading: true }
wrapper.vm.$forceUpdate() Or you can pass in a parent component with the const Parent = {
data() {
return {
loading: "asdas"
};
}
};
const wrapper = shallowMount(TestComponent, {
parentComponent: Parent
}); |
Can anyone share context of why the first solution was removed? I find this cleaner... mocks: {
$root: {}
} Anyways, using the above suggestion for now indeed works well |
In my mounted function $root is called so I have to mock it before mounting. Than it is not possible overwrite set wrapper.vm.$root afterwards. |
recommend,it‘s good! |
const Parent = {
template: '<div id="app">Modal Body</div>',
data() {
return {
loading: 'asdas'
};
}
};
const wrapper = shallowMount(TestComponent, {
parentComponent: Parent
}); In my TestComponent mounted I have ``
Which throws HierarchyRequestError: The operation would yield an incorrect node tree. Here you can try https://codesandbox.io/s/quiet-snow-tzdf5?file=/src/Sample.spec.js |
After more than 2 years I am still stuck on this issue. |
ParentComponent doesn't work if the data key starts with $ const Parent = {
data() {
return {
$api: client
};
}
}; Any work around for this ? |
I also have a mounted function in which $root is called and this solution worked for me. |
Version
1.0.0-beta.12
Reproduction link
https://codesandbox.io/s/n92wj49kn0
Steps to reproduce
Try to set data into localVue and get this from testing env
What is expected?
Expected testData === 'testData'
What is actually happening?
testData === undefined
I can not understand how to throw data into localVue
The text was updated successfully, but these errors were encountered: