in my component for that test I have... something ...
# vue
l
in my component for that test I have... something like
const state = reactive({...});
how can I access state from within my test?
w
you should be able to use
wrapper.vm
for this, see the Vue Test Utils docs: https://test-utils.vuejs.org/api/#vm For props you can use
wrapper.props
as opposed to `propsData`: https://test-utils.vuejs.org/api/#props-1 I'm assuming Vue 3, there are different set of those docs for Vue 2 so ymmv. In general though, I would consider these a last resort, and would recommend a test that verifies these values from the UI side or from the events the component should emit when they change, which can avoid your test depending on the names and behavior of the internals of a component. But if you do need to be in there, following the VTU docs should work.
l
thanks for getting back to me, wrapper.vm.$data, which I tried yesterday did not work. This was not needed for my tests, I have all my tests working well testing UI interactions and behavior, but in the case I wanted to assert against a value of a ref within my component, I want to know how to do that.. thank you again 🙏🏻
7 Views