vue-test-utils-compat provides a critical compatibility layer for migrating existing Vue 2 test suites written with `@vue/test-utils` v1 to run seamlessly on `@vue/test-utils` v2 and Vue 3. This package, currently at version 0.0.15, is designed to ease the transition burden by allowing developers to upgrade their Vue components to Vue 3 first, and then address test migrations, leveraging Vue 3's migration build. It achieves this by providing numerous compatibility flags that can be configured to mimic v1 behavior, addressing differences in mounting options, wrapper APIs, and event handling. Its release cadence is tied to the needs of the Vue 2 to Vue 3 migration process. A key differentiator is its extensive configuration options, allowing granular control over which v1 behaviors are re-enabled, facilitating a gradual and less disruptive migration path.
npm install vue-test-utils-compatVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to install the compatibility layer for `@vue/test-utils` v2 in a Vue 3 project and provides a basic example of testing a component with v1-style APIs.
Run your existing v1 test suite with the latest `@vue/test-utils` v1 and resolve all reported deprecation warnings and errors. Consult the `@vue/test-utils` v1 documentation for specific deprecation fixes.
For Vue 3 (full mode), import `h` directly from 'vue'. For Vue 3 migration build (Vue 2 mode), ensure you mount a temporary app to capture the `h` function, as shown in the package's documentation. Incorrect `h` will lead to runtime errors during test execution.
Review the list of compatibility flags in the `vue-test-utils-compat` documentation and enable/disable specific flags as needed. Debug tests thoroughly after migration, focusing on interactions that rely heavily on v1-specific APIs. Be prepared to gradually refactor problematic tests to native VTU v2 APIs where full compatibility is not achievable.
Plan for a phased migration where `vue-test-utils-compat` is used temporarily, followed by a dedicated effort to rewrite tests using `@vue/test-utils` v2 and Vue 3's native testing patterns for long-term maintainability and performance.
Ensure `@vue/test-utils` is correctly installed and imported, and that `installCompat` receives the actual `VueTestUtils` object (e.g., `import * as VueTestUtils from '@vue/test-utils'`).
Pass the `h` function imported from 'vue' (for Vue 3) or correctly retrieved from a Vue 3 migration build instance to `installCompat`.
Ensure you are targeting a DOM element (`wrapper.find('p')`) and not a component (`wrapper.findComponent(MyComponent)`) when expecting DOM-specific methods like `text()`. Also verify the selector correctly matches an element present in the rendered output.