Registry / testing / vue-i18n-jest

vue-i18n-jest

JSON →
library1.1.1jsnpmunverified

vue-i18n-jest is a specialized Jest transformer designed to enable the correct parsing and transformation of `<i18n>` custom blocks within Vue Single File Components (SFCs) during unit testing. It specifically targets Vue 2 applications and integrates with `vue-jest@v4`. This package is crucial for developers who store their internationalization messages directly within their Vue components and need Jest to understand and process these blocks for testing. The current stable version is 1.1.1, released in October 2021. Its release cadence has been sporadic. It differentiates itself by providing a dedicated bridge for `vue-jest` to handle i18n custom blocks, which is not natively supported by `vue-jest` alone for Vue 2 testing environments.

npm install vue-i18n-jest
INSTALL
IMPORT
SIG · VUE-I18N-JEST
V
vue-i18n-jest
testingjavascriptv1.1.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Jest Configuration (Vue SFC i18n blocks)
// jest.config.js module.exports = { // ... other Jest configurations globals: { 'vue-jest': { transform: { 'i18n': 'vue-i18n-jest' // This line enables the transformer for i18n blocks } } } };
// jest.config.js module.exports = { transform: { '^.+\.vue$': 'vue-i18n-jest' // Incorrectly trying to use it as the primary Vue transformer } };
vue-i18n-jest is consumed as a string reference within Jest's configuration. It must be nested under `globals['vue-jest'].transform.i18n` to handle custom i18n blocks within Vue 2 SFCs, complementing `vue-jest`.
Direct Transformer Reference (Less Common)
// jest.config.js module.exports = { transform: { '^.+\.(i18n|json5)$': 'vue-i18n-jest' // Example: directly mapping i18n custom blocks if extracted to separate files } };
import { process } from 'vue-i18n-jest'; // This package exports a default function, not named exports for direct usage
While its primary use is through `vue-jest`, `vue-i18n-jest` is technically a Jest transformer and could be mapped directly to specific file extensions (e.g., `.i18n` or `.json5` if your i18n content lives in standalone files). Direct programmatic import of its module is not its typical use case.
CommonJS/ESM Module Import (Discouraged)
const i18nTransformer = require('vue-i18n-jest'); // or import i18nTransformer from 'vue-i18n-jest';
Jest transformers are loaded by their string name during configuration. Attempting to manually `require` or `import` the module into JavaScript/TypeScript code for direct invocation of its `process` method is not the standard or recommended way to use this package.

This configuration snippet for `jest.config.js` demonstrates how to integrate `vue-i18n-jest` into your Jest setup to correctly parse `<i18n>` custom blocks within Vue 2 Single File Components when using `vue-jest`.

// jest.config.js const path = require('path'); module.exports = { // Specify test environment (e.g., jsdom for browser-like DOM environment) testEnvironment: 'jsdom', // List of file extensions Jest should look for moduleFileExtensions: ['js', 'json', 'vue', 'ts'], // How to transform files based on their extension transform: { '^.+\.vue$': 'vue-jest', // Use vue-jest for Vue SFCs '^.+\.js$': 'babel-jest', // Use babel-jest for JavaScript files '^.+\.ts$': 'ts-jest' // Use ts-jest for TypeScript files (if applicable) }, // Global settings for specific transformers, especially for vue-jest globals: { 'vue-jest': { // Enable vue-i18n-jest to process <i18n> blocks within Vue SFCs transform: { 'i18n': 'vue-i18n-jest' } } }, // Set up module name mapping for imports, e.g., '@/components' for 'src/components' moduleNameMapper: { '^@/(.*)$': path.resolve(__dirname, 'src/$1') }, // Snapshot serializer for Vue components (recommended for better readability) snapshotSerializers: [ 'jest-serializer-vue' ] // Ensure vue and vue-template-compiler are installed as devDependencies. // This setup assumes a basic Vue 2 project with TypeScript (optional) and Babel. };
Debug
Known issues
breakingStarting with version 1.1.0, Node.js version 10 is no longer supported. Projects must upgrade to Node.js 12 or newer to use this version and subsequent releases.
fix
Upgrade your Node.js runtime to version 12 or higher. Check your project's `engines` field in `package.json` and your CI/CD environment.
affects: >=1.1.0
gotchaThis transformer is specifically designed for `vue-jest@v4`, which is used for testing Vue 2 applications. It is not compatible with `vue-jest@v5` or testing environments for Vue 3.
fix
Ensure your project is a Vue 2 application and `vue-jest` version 4.x is installed. For Vue 3, alternative solutions for i18n block transformation might be required or are handled differently by `vue-jest` v5.
affects: >=0.1.0
gotchaAs of v1.1.1, `vue-jest` was removed from `vue-i18n-jest`'s peerDependencies. While no longer explicitly listed, `vue-jest@v4` remains a functional dependency for this package to operate correctly.
fix
Manually ensure that `vue-jest` (specifically version 4.x) is installed in your project's `devDependencies` alongside `vue-i18n-jest`.
affects: >=1.1.1
gotcha`vue` and `vue-template-compiler` are essential peer dependencies for any Vue 2 testing setup using `vue-jest`. Failure to install compatible versions will lead to Jest errors.
fix
Ensure `vue` (e.g., `^2.5`) and `vue-template-compiler` (e.g., `^2.5`) are installed as `devDependencies` in your project, matching the required peer dependency versions.
affects: >=0.1.0
Errors
Common errors & fixes
Jest encountered an unexpected token. This usually means that you are trying to import a file which Jest cannot parse, e.g. a .vue file with a custom block you have not configured a transformer for. (SyntaxError: Unexpected token <)
The `vue-i18n-jest` transformer is not correctly configured in `jest.config.js`, causing Jest to fail when parsing `<i18n>` blocks within Vue SFCs.
fix
Verify that `vue-i18n-jest` is installed and correctly added to your `jest.config.js` under `globals['vue-jest'].transform.i18n` as shown in the quickstart example.
Error: Cannot find module 'vue-i18n-jest' from 'jest.config.js'
The `vue-i18n-jest` package is referenced in `jest.config.js` but is not installed as a development dependency.
fix
Install the package using your preferred package manager: `npm install --save-dev vue-i18n-jest` or `yarn add -D vue-i18n-jest`.
Minimum Node.js version of 12.0.0 is required. You are running 10.x.x.
Attempting to use `vue-i18n-jest` version 1.1.0 or newer with an unsupported Node.js runtime (version 10.x).
fix
Upgrade your Node.js environment to version 12 or a later compatible version. Consult your project's `.nvmrc` or CI/CD configuration.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
vuerequiredPeer dependency required for the Vue 2 applications being tested.
vue-template-compilerrequiredPeer dependency critical for compiling Vue 2 templates and SFCs in a Jest environment.
Agent activity
14 hits · last 30 days
node
12
Resources
vue-i18n-jest — npm install vue-i18n-jest · libregistry