Closed TomBell95 closed 1 year ago
Hi! Thanks for the question.
We should be able to access functions or variables inside the component
I would have assumed, just like vue/test-utils, we could still access anything exposed by the component?
Actually no, this is not the philosophy of Testing Library.
If there's a specific use case that you can't test without accessing internals (from my own experience this is unlikely and usually related to specific stuff that plugs into Vue internals), I'd recommend writing that test using @vue/test-utils
(Vue Testing Library uses it under the hood, so the dependency is already there. You can simply import it).
Describe the bug When testing using
<script setup>
, the component is closed by default and we should have access to anything we expose through defineExpose? Is this a limitation of using testing-library compared to vue/test-utils where you can access anything exposed by the component?Error:
TypeError: Cannot destructure property 'expose' of 'undefined' as it is undefined.
To Reproduce App.vue
App.test.js
Expected behavior
We should be able to access functions or variables inside the component. As per the vue docs on defineExpose when using
<script setup>
. I understand that the philosophy behindtesting-library
is behaviour based testing, but there are edge cases where this is valid.I would have assumed, just like vue/test-utils, we could still access anything exposed by the component? The equivalent is
wrapper.vm.FOO
(link here) - is this possible in testing-library?Additional context
I raised this my specific use case on stackoverflow here: https://stackoverflow.com/q/75298194/15369125