test-utils icon indicating copy to clipboard operation
test-utils copied to clipboard

No data on Option API component returned by mountSuspended

Open kingyue737 opened this issue 2 years ago • 3 comments

Environment


  • Operating System: Linux
  • Node Version: v18.18.0
  • Nuxt Version: 3.9.3
  • CLI Version: 3.10.0
  • Nitro Version: 2.8.1
  • Package Manager: [email protected]
  • Builder: -
  • User Config: devtools
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-ddvycp

Describe the bug

const wrapper = await mountSuspended(OptionAPIComponent)

wrapper.vm.$data is empty wrapper.setData({...data}) will result into error:

TypeError: Cannot add property, object is not extensible

Furthermore, I cannot call any method of the component instance:

TypeError: wrapper.vm.myMethod is not a function

Additional context

Component written in composition api doesn't have this issue. @vue/test-utils doesn't have this issue.

Logs

No response

kingyue737 avatar Jan 25 '24 06:01 kingyue737

I see the same issue, however, my component is written with the composition API.

sei-jdshimkoski avatar Mar 08 '24 14:03 sei-jdshimkoski

I see the same issue, however, my component is written with the composition API.

Did you guys found a solution? i'm having the same issue in nuxt 3 app

georiv avatar Apr 11 '24 19:04 georiv

I'm having the same issue with mountSuspended, but it works when I use mount from @vue/test-utils.

Vesely avatar Aug 02 '24 20:08 Vesely

I can confirm setData leads to the above mentioned error message with mountSuspended. Just wanted to share my workaround:

const wrapper = await mountSuspended(MyComponent, options)
wrapper.setData = data => wrapper.findComponent({ name: 'MountSuspendedComponent' }).setData(data)

But I think this should be fixed in the library, as setData is currently not working.

sebbayer avatar Jan 29 '25 17:01 sebbayer