question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Composition API SFC test issue when using Vue 2.7 or the compat Mode

See original GitHub issue

Subject 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

image

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:open
  • Created a year ago
  • Reactions:12
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
kingyue737commented, Jul 21, 2022

@lmiller1990 We cannot migrate to Vue 2.7 without test😭😭

2reactions
lmiller1990commented, Jul 21, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue 2.7 "Naruto" Released
The Composition API is backported using Vue 2's getter/setter-based reactivity system to ensure browser compatibility.
Read more >
@vue/compat - npm
The migration build runs in Vue 2 mode by default - most public APIs behave exactly like Vue 2, with only a few...
Read more >
Jest don't mount composition-api component on Vue 2.7 + TS ...
Had the same error and the problem turned out to be the format of my imports inside of the child component of a...
Read more >
Vue 3.1 - Official Migration Build from Vue 2 to 3 - This Dot Labs
@vue/compat (aka "the migration build") is a build of Vue 3 that ... Composition API and some other Vue 3 features to the...
Read more >
vue 2.7 defineprops | The AI Search Engine You Control
When using the compat mode or the 2.7 build, the unit tests start failing when using the composition api in the SFC syntax....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found