-
Notifications
You must be signed in to change notification settings - Fork 262
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
Bug: defineExpose does not work with functions #1731
Comments
Hey@marina-mosti Thanks for the repro. I'm off work right now, so I'll take a deeper look in a few weeks, but that does not surprise me: we "cheat" to have access to the functions if they are not exposed, by using the internal proxy of what is available in the template. As Can you check that's what I suspect? If |
Hey @cexbrayat thanks for the reply, sadly no - it still fails the same way. <script setup lang="ts">
// imported components are also directly usable in template
import { ref } from 'vue'
import Hello from './Hello.vue'
const count = ref(0)
const inc = () => {
count.value++
}
const resetCount = () => {
count.value = 0
}
defineExpose({
count,
resetCount
})
</script>
<template>
<button @click="inc" @hover="resetCount">{{ count }}</button>
<Hello />
</template> I saw your "cheat" with the vm.proxy, but its not getting populated 😓 |
Hmm interesting, I'll need to take a deeper look then (probably not until one or two weeks, so if someone else is up to it, feel free) |
I verified this does work in production - Test Utils only bug, I guess. Where do we "cheat" @cexbrayat? I forgot how Somewhere around here I guess? https://github.com/vuejs/test-utils/blob/main/src/vueWrapper.ts#L47-L62. I'm not entirely clear what |
@marina-mosti I have added your reproduction code to the tests and run it successfully #1735. I think you updated If this wasn't the case and it's still failing then please reopen this issue |
🤦🏻♀️ Uff. Terribly sorry |
Awesome, thanks @freakzlike for looking into it ❤️ |
Turns out after tons of trial and error that the actual problem was that the exposed function was named defineExpose({
count,
do: _do
}) Changing the name makes it be correctly exposed again |
Describe the bug
When using
script setup
+defineExpose
, exposed functions are not found within VTU.vm
To Reproduce
Modify
ScriptSetup_Expose.vue
component as follows:Within
expose.spec.ts
append to the test:Expected behavior
The test should pass, instead we get
Related information:
@vue/test-utils
version: 2.x.xVue
version: 3.x.xnode
version:npm
(oryarn
) version: Ran with pnpm on top of main branchAdditional context
SFC of component shows correct binding of function to
expose
call https://sfc.vuejs.org/#eNptUcFuwjAM/RUrF0BAwxkVtGmatI/IpQSXhaVOlKRsU9V/n9PQscNufvbzs/08iGfvq1uPYi/qqIPxCSKm3oNt6HJQIkUljoqkBNN5FxKeQTuOCClFaAJCY6ODswmok/2GPjYni2AIEnbeNgkVlU4YIGALI7TBdbDgmYvf0hta6+6FSk4oL8UERdpRTDy0pwSHLLHcreasIc255QoORxgUQaFVt8b2uF4rGmdiQL7q5a7xP58Lu6lD0RlbQ/j65V3E5YO3ydFDicm8SC2LbWwSg/loRgD1qU/JETxpa/QHm8nrspvDcL9mHGtZKIVeXJAMavlHSGxEsWnbNb66Rkf8rGkrVpwK/KN9uSfn2LiMlXhPyce9lLHV2c1rrFy4SI6qwONNhxXGbnsK7jNiYGElsgQ7MIrxBzIhu4w=The text was updated successfully, but these errors were encountered: