ESLint Plugin for Vue Test Utils

1.0.1 · active · verified Sun Apr 19

The `eslint-plugin-vue-test-utils` package is an ESLint plugin dedicated to enforcing best practices and identifying potential issues when using the `@vue/test-utils` library for testing Vue components. It helps developers maintain high-quality and future-proof test suites by flagging deprecated API usages, inconsistent patterns, and common anti-patterns. The current stable version is 1.0.1, indicating a mature initial release. While a strict release cadence isn't explicitly stated, the recent v1.0.1 release with multiple feature additions and documentation improvements suggests active development. Its core differentiator lies in its specialized focus on `@vue/test-utils`, providing rules that are context-aware of VTU's API changes and version-specific behaviors, often with autofixing capabilities. This enables smoother upgrades of `@vue/test-utils` and helps keep test code consistent without needing manual audits for deprecated features. It complements broader ESLint Vue plugins by offering specific, targeted linting for testing concerns.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install the plugin, configure it in an `.eslintrc.js` file to use its recommended rules, and manually specify individual rules. It also shows the option to set the Vue Test Utils version manually, which is crucial for correct linting in certain project setups.

npm install --save-dev eslint eslint-plugin-vue-test-utils @vue/test-utils vue

// .eslintrc.js
// Make sure you have @vue/test-utils installed and configured for your project
module.exports = {
  root: true,
  env: {
    node: true,
    'vue/setup-compiler-macros': true, // Essential for Vue 3 SFC setup script syntax
    jest: true // Or 'vitest: true' if using Vitest for tests
  },
  parserOptions: {
    ecmaVersion: 2020,
    sourceType: 'module'
  },
  extends: [
    'eslint:recommended',
    'plugin:vue/vue3-recommended', // Example: Use Vue 3 recommended rules
    'plugin:vue-test-utils/recommended' // Enable all recommended vue-test-utils rules
  ],
  plugins: [
    'vue-test-utils'
  ],
  rules: {
    // Override or add specific vue-test-utils rules
    'vue-test-utils/no-deprecated-wrapper-functions': 'warn',
    'vue-test-utils/no-deprecated-mount-options': 'error'
  },
  settings: {
    // Manually specify Vue Test Utils version if auto-detection fails (e.g., in monorepos).
    // This can be useful for rules that adapt behavior based on the VTU version.
    // "vtu": {
    //   "version": require('@vue/test-utils/package.json').version || "2.0.0"
    // }
  }
};

view raw JSON →