Closed as not planned
Closed as not planned
Description
Describe the bug
i use <script setup/>
composite component api and want to use the data : () => Record<string, unknown>
callback in mount/shallowmount
To Reproduce
following test fails if used with the component below
it('should handle setData on composition api component', async () => {
const wrapper = mount(SimpleData)
expect(wrapper.html()).toEqual(
'<div>sArray:[\n "initialA",\n "initialB"\n ]|s:initialC</div>'
)
await wrapper.setData({
dataStringArray: ['setA', 'setB'],
dataString: 'setC'
})
expect(wrapper.html()).toEqual(
'<div>sArray:[\n "setA",\n "setB"\n ]|s:setC</div>'
)
})
Component SimpleData.vue
<template>
<div>sArray:{{dataStringArray}}|s:{{dataString}}</div>
</template>
<script setup lang="ts">
import {ref} from "vue";
const dataStringArray = ref<string[]>(["initialA","initialB"])
const dataString = ref<string>("initialC")
</script>
while this test (using an inline declaration will not fail)
it('should handle setData on inline component component', async () => {
const Component = {
template: `<div>sArray:{{dataStringArray}}|s:{{dataString}}</div>`,
data: () => ({
dataStringArray: ['initialA', 'initialB'],
dataString: 'initialC'
})
}
const wrapper = mount(Component, {
data: () => {
return {
dataStringArray: ['setA', 'setB'],
dataString: 'setC'
}
}
})
expect(wrapper.html()).toEqual(
'<div>sArray:[\n "setA",\n "setB"\n ]|s:setC</div>'
)
})
Expected behavior
both tests should not fail
Related information:
@vue/test-utils
version: 2.2.4Vue
version: 3.2.33node
version: 16.18.0npm
version: 8.19.2