vue-jest is a Jest transformer designed to enable testing of Vue Single File Components (SFCs) within a Jest environment. Version 3.0.7 is part of the legacy branch primarily supporting Vue 2.x applications and compatible with Jest versions up to Jest 27. This package transpiles Vue SFCs, including script, template, and style blocks, into a format Jest can understand. While still functional for older projects, it has been largely superseded by the `@vue/vue2-jest` and `@vue/vue3-jest` packages, which offer dedicated support for Vue 2 and Vue 3 respectively, alongside Jest 28 and 29. Developers working on new projects or upgrading Jest should use the scoped `@vue` packages. The release cadence for `vue-jest@3.x` is now minimal, focused mainly on critical fixes for existing users, as active development has shifted to the scoped packages. Its key differentiator was being the official Vue team's solution for Jest testing before the package split.
npm install vue-jestVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure `vue-jest` in `jest.config.js` for testing a basic Vue 2 component, including an example component and its corresponding unit test using `@vue/test-utils`.
Install `@vue/vue2-jest` or `@vue/vue3-jest` and update `jest.config.js` transform entry to `'@vue/vue2-jest'` or `'@vue/vue3-jest'`. Ensure compatibility with your Jest and Vue versions.
Ensure `vue-template-compiler` is installed with the exact same version as `vue`. For example, `npm install vue-template-compiler@<vue-version>`.
Verify your `jest.config.js` includes `ts-jest` or `babel-jest` for `.ts` files and that your `tsconfig.json` is correctly configured to transpile for your target environment. Ensure `tsconfig.json` includes `vue` types if necessary.
Plan to migrate to the appropriate scoped `@vue` package to receive active development, bug fixes, and Jest 28/29+ compatibility.
`npm install vue-template-compiler@<vue-version>` or `yarn add vue-template-compiler@<vue-version>`. Ensure the version matches your installed `vue` package.
Check your `jest.config.js` `transform` entry for `vue-jest`: `{'^.+\.vue$': 'vue-jest'}`. Also, ensure `babel-jest` is configured for JavaScript files and `transformIgnorePatterns` allows transformation of relevant modules if needed.Ensure `babel-jest` (or `ts-jest` for TypeScript) is correctly configured in `jest.config.js` to transpile ES modules. For Babel, verify your `.babelrc` or `babel.config.js` includes `@babel/preset-env` with `modules: 'commonjs'` (or `auto` if Babel 7.x).