-
Notifications
You must be signed in to change notification settings - Fork 254
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
lifecycle methods in child components not invoked #727
Comments
Cannot start and test your project because of many errors. Do you really need custom webpack configuration? Please use vue-cli |
It's based on this but I'll try to make another repro later today. Btw, what kind of errors? |
Sounds like a bug to me - this should be quite easy to repro in this repository if anyone wants to give it a go. I have to work on the Vue compat build stuff atm, but I can look into this after. |
I have created a simple repro: https://github.com/standbyoneself/vue-slot-hooks. The only one test is in The problem is in this part of code:
You passed your slot as an object so it simply renders without calling any lifecycle hooks.
What is the solution? Check
|
Is there still a problem or is this fixed as of rc 10? |
I didn't know about
Should I create a new issue for this? Or did I do something wrong? |
Please, upgrade a
And it will work |
@standbyoneself ah thanks. from However, it still doesn't work. I also checked out this repo(https://github.com/standbyoneself/vue-slot-hooks) and updated VTU to mount(Parent, {
slots: {
default: Child,
},
}); |
Are you on the |
@standbyoneself Oh I misunderstood what you said earlier. I thought you meant "either upgrade to rc.10 or use template". Do we have to use |
Since I am not a core developer I can not properly answer your question but I suppose that |
@standbyoneself Thanks for the explanation. I wasn't aware of that. However, just to make sure, I did some tests but it's not true. vue 2: https://codesandbox.io/s/dank-platform-tthyo?file=/src/components/Test.vue:0-136 Both vue versions invoke lifecycle methods. If that's the case, VTU should support too. What do you think @lmiller1990 ? |
Sure, I make this supposition only in the context of using the VTU^2 and slots accordingly to the it's implementation, I did not say that you can not have lifecycle hooks inside the components with |
This should work, seems like a bug. You can use lifecycles with
Turns into:
Or something like that. Anyway, I reproduced it here: #743 for easy debugging. |
Ok so this works fine: it('triggers child component lifecycles', async () => {
const parentMounted = jest.fn()
const childMounted = jest.fn()
const Parent = defineComponent({
mounted() {
parentMounted()
},
render() {
return h(this.$slots.default!)
}
})
const Child = defineComponent({
render() {
return h('span')
},
mounted() {
childMounted()
}
})
const wrapper = mount(Parent, {
global: {
components: { Child },
},
slots: {
default: Child
}
})
await flushPromises()
expect(parentMounted).toHaveBeenCalled()
expect(childMounted).toHaveBeenCalled()
}) This fails, though:
Problem is the ❌ |
Problem is here https://github.com/vuejs/vue-test-utils-next/blob/6e0904c6dc9f6e17045ad69773a33926a54bc872/src/mount.ts#L265-L266 We only render Work around would be use one of the other syntaxes for now. |
Ok, fixed it: #743 Please review, this will be in the next release. |
Lifecycle methods in child components seem to be not invoked.
↑ https://github.com/eunjae-lee/vue-test-utils-snapshot-2/blob/master/src/Test.spec.ts#L11-L37
I expect console log from
Child
or evenError
being thrown atcreated
, but I don't see anything and it successfully(?) prints out the html.However, this workaround works:
The text was updated successfully, but these errors were encountered: