jest-vue-preprocessor is a Jest transformer designed to enable the testing of Vue Single File Components (SFCs) within a Jest environment. Specifically, it allows Jest to correctly parse and process `.vue` files by transforming their templates and scripts into a format Jest can understand, supporting both ES6 (via Babel) and TypeScript. The current stable version is 1.7.1. This package was largely based on `vueify` and aimed to bridge the gap for Vue 2 projects wanting to use Jest for unit testing. Its primary differentiation is providing out-of-the-box support for `.vue` file compilation within Jest's isolated test environment, which Jest does not handle natively. However, it is an older package, last updated in 2019, and is primarily compatible with Vue 2.x and specific older versions of `vue-template-compiler`. Newer Vue projects (Vue 3 and above) typically use `vue-jest` for their testing needs due to significant breaking changes in Vue's compilation pipeline. Given its age and lack of recent updates, its release cadence is effectively ceased, and it should be considered abandoned for new projects.
npm install jest-vue-preprocessorVerified import paths — ran on the pinned version, not inferred.
This configuration snippet shows how to integrate `jest-vue-preprocessor` into your `package.json`'s Jest settings, enabling Jest to process `.vue` files and use Babel for JavaScript transformation.
For Vue 3 projects, migrate your Jest setup to use `vue-jest` (version 5 or higher) or a similar modern transformer designed for Vue 3.
Ensure your project explicitly installs `vue-template-compiler@2.6.x` as a development dependency (`npm install --save-dev vue-template-compiler@2.6.x` or `yarn add -D vue-template-compiler@2.6.x`).
Add a `moduleNameMapper` entry to your Jest configuration, mapping your aliases to their physical paths (e.g., `"^@/(.*)$": "<rootDir>/src/$1"`).
Verify that `jest-vue-preprocessor` is listed correctly in your Jest `transform` configuration (e.g., `".*\\.(vue)$": "<rootDir>/node_modules/jest-vue-preprocessor"`) and that the package is installed.
Install the correct version of the peer dependency: `npm install --save-dev vue-template-compiler@2.6.x` or `yarn add -D vue-template-compiler@2.6.x`.
Add a `moduleNameMapper` configuration to your Jest settings that maps your project aliases to their corresponding file paths, e.g., `"^@/(.*)$": "<rootDir>/src/$1"`.