vue-jest
Jest Vue transformer
A Jest transformer that compiles Vue single-file components so you can write automated tests for them.
Vue Jest is a tool that lets you test Vue components using Jest, a popular testing framework. When you write Vue components as single-file components (a .vue file that bundles HTML, JavaScript, and styling together), Jest doesn't natively understand that format. Vue Jest translates those .vue files into regular JavaScript that Jest can read and test.
Here's how it works in practice. You install vue-jest as a development dependency, then tell Jest in your configuration file to use vue-jest whenever it encounters a .vue file. Vue Jest takes the script (JavaScript logic) and template (HTML structure) from each component, compiles them into something Jest understands, and hands them over for testing. The tool also preserves source maps, which means if a test fails, the error message points you to the original .vue file rather than the compiled output, making debugging easier.
The tool supports various flavors of JavaScript and templating syntax that developers might use. For scripts, you can write in TypeScript or CoffeeScript instead of plain JavaScript. For templates, you can use Pug, Jade, or HAML instead of standard HTML. One important limitation: vue-jest doesn't compile the styling section of your components, so CSS or SCSS in your .vue files won't be processed during testing—only the interactive parts of your component get tested.
You'd use this if you're building a Vue application and want to write automated tests for your components. Instead of manually clicking through your app to verify it works, you write test code that exercises your components and checks the output. Examples in the README show how teams use vue-jest alongside testing libraries like Vue Test Utils to write comprehensive component tests.
Where it fits
- Write automated Jest tests for Vue single-file components instead of manual clicking.
- Debug failing tests with source maps pointing back to the original .vue file.
- Test components written with TypeScript or CoffeeScript scripts.
- Combine with Vue Test Utils for comprehensive component test suites.