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.

Reactivity issues with @vue/compat

See original GitHub issue

Hi! 👋

Reactivity does not seem to work when using the vue compat build.

For example these tests will work with vue 3, but not with @vue/compat:

import {ref, onMounted, defineComponent} from 'vue';
import {it} from 'vitest';
import {render} from '@testing-library/vue';

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

const TestAsync = defineComponent({
    template: '<div><div>{{ mountText }}</div><div>{{ asyncText }}</div></div>',

    setup() {
        const mountText = ref();
        const asyncText = ref();

        onMounted(() => {
            mountText.value = 'mounted';
        });

        sleep(0).then(() => {
            asyncText.value = 'async';
        });

        return {
            mountText,
            asyncText,
        };
    },
});

it('should show onMount text', async () => {
    const {findByText} = render(TestAsync);
    await findByText('mounted');
});

it('should show async text', async () => {
    const {findByText} = render(TestAsync);
    await findByText('async');
});

In compat mode it will show:

TestingLibraryElementError: Unable to find an element with the text: async. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.

<body>
  <div>
    <div>
      <div />
      <div />
    </div>
  </div>
  <div>
    <div>
      <div />
      <div />
    </div>
  </div>
</body>

To Reproduce Steps to reproduce the behavior:

Use this minimal reproduction repo: https://github.com/Weetbix/vue-compat-composition-api-bug-repo

Expected behavior

The tests should pass, and the text should be found in the dom

Related information:

  • @testing-library/vue version: 6.6.0
  • Vue version: 3.2.37
  • @vue/compat version: 3.2.37
  • node version: v16.13.2
  • npm (or yarn) version: 1.22.19

Additional context

We have a very large code base and were hoping to migrate to Vue 3 by using compat mode. It’s working at runtime but we are running into reactivity issues in the test suites.

Note: This issue also exists in the new vue 2.7` build with the backported composition API.

It does not occur in Vue 2.6 when using the @vue/composition-api plugin.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
lisilinhartcommented, Jul 8, 2022

I encountered the same problem in the Vue 2.7 build with the backported composition API. The old option api components test without a problem, but when using the SFC syntax the reactive content will be missing.

Related information:

  • @testing-library/vue version: 5.8.3
  • Vue version: 2.7.4
  • node version: v16.11.1
  • npm (or yarn) version: 1.22.18

This problem also occurs when using import { mount } from '@vue/test-utils' itself on that version

1reaction
lisilinhartcommented, Jul 11, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

@vue/compat - npm
@vue/compat (aka "the migration build") is a build of Vue 3 that provides configurable Vue 2 compatible behavior.
Read more >
Reactivity issue in vue component - Stack Overflow
Edits : I tried to use a computed property in the component without success. I found a way to make it work by...
Read more >
@vue/compat | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
Migration to Vue 3 - GitLab Docs
They might not work with @vue/compat , so we need a strategy to use an updated ... issues in the demo project, it...
Read more >
vue/compat/README.md - UNPKG
The CDN for @vue/compat. ... 7, ### Intended Use Cases ... removed (use `reactive`) | [link](https://vuejs.org/api/reactivity-core.html#reactive) |.
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