Composition API SFC test issue when using Vue 2.7 or the compat Mode
See original GitHub issueSubject of the issue
Hi,
this issue is created, after another issue was opened here in vue-testing-library
: https://github.com/testing-library/vue-testing-library/issues/275
The core of the problem seems to be in @vue/test-utils
:
When using the compat mode or the 2.7 build, the unit tests start failing when using the composition api in the SFC syntax. I tried using the composition api in a SFC synctax from the 2.7 build itself and this behaviour appears:
<script setup>
import { ref, onBeforeMount, defineProps } from 'vue'
defineProps({
msg: {
type: String,
default: ''
},
})
const label = ref('init')
onBeforeMount(() => {
label.value = 'mounted'
})
</script>
<template>
<div>{{ msg }} - {{ label }}</div>
</template>
results in this testing html
If we use the regular export default
syntax with the composition api, it seems to be still working.
Steps to reproduce
To reproduce the behavior:
Use this minimal reproduction repo: https://github.com/lisilinhart/vue-2.7-sfc-test-bug-repo
Expected behaviour
When mounting the component with the composition API in a sfc syntax, it should render the component correctly like it does for the options api.
Actual behaviour
The asynchronous text is never rendered in the mounted component.
Possible Solution
Issue Analytics
- State:
- Created a year ago
- Reactions:12
- Comments:14 (3 by maintainers)
Top GitHub Comments
@lmiller1990 We cannot migrate to Vue 2.7 without test😭😭
The whole back porting of Vue 3 to Vue 2 is making a lot of work for this repo (and old versions of Vue Jest).
I have no bandwidth to work on Vue Test Utils v1/Vue 2/Vue Jest combo right now.
If there’s a bug in Vue 3/Vue Test Utils 2 (different repo, as mentioned above) we will actively try to fix/address it.