-
Notifications
You must be signed in to change notification settings - Fork 258
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
The expose
methods cannot be got on the vm
#683
Comments
@zouhangwithsweet Thank you for opening an issue. Which version of VTU are you using? If it is version Try with |
OK, sir. |
There is still have the issue with Reproduction test.vue <script lang="ts">
import { h } from 'vue'
export default {
name: 'Test',
setup(props: any, { expose }: any) {
const alert = () => {
console.log('message')
}
expose({
alert,
})
return () => h('div', { class: 'box' }, ['message'])
},
}
</script> spec.ts test('test', () => {
const wrapper = mount(() => h(Test, {}, []), {
props: {},
})
console.log(wrapper.findComponent({ name: 'Test' }).vm) // empty {}
}) |
As soon as I saw this I thought it might be related to #663 as well. But it looks like it isn't. Does this code work outside of Test Utils? Even after reading the |
Seems we have a bug somewhere. I made this example: const Comp = defineComponent({
setup(props, { expose }) {
const bar = () => {}
expose({ bar })
return () => h('div')
}
})
const app = createApp(Comp)
const $app = app.mount(document.createElement('div')) I was able to do Doing mount with test('test', () => {
const Comp = defineComponent({
setup(props, { expose }) {
const bar = () => {}
expose({ bar })
return () => h('div')
}
})
const wrapper = mount(Comp)
console.log(wrapper.vm) // contains `bar`
}) And was able to expose something on the top level. Unrelated, but I am not clear on the I think we need to dive into As an aside, what is your use case? Why do you want to expose |
I think |
Something is weird with |
@lmiller1990 Original component (normal setup): <script lang="ts">
import { h } from 'vue'
export default {
name: 'Test',
setup(props: any, { expose }: any) {
const alert = () => {
console.log('message')
}
expose({
alert
})
return () => h('div', { class: 'box' }, ['message'])
}
}
</script> Component with script setup: <script setup lang="ts">
function alert() {
console.log('message')
}
defineExpose({
alert
})
</script>
<template><div>hello</div></template> test: it('works', () => {
const wrapper = mount(ExposeInSetup);
expect(wrapper.vm.alert).toBeDefined()
}) And for both cases it works as expected. When we mount something like
This works as expected :) |
Oh, ok! I am guessing there was just some bug in an earlier version of Vue 3, or we had incompatible versions. Good to know this is working now. |
The
vm
doesnot have thealert
methods.The text was updated successfully, but these errors were encountered: